Storing array from another class in java

Onitech

I know that there's tons of ways to store an array from another class but what is the best approach that can be easily understood by everyone, even beginners?

Here is the sample code:

1st class: // this is where to get the array to be stored

public class Example{
    private int[] Numbers = {3,2,1}//sample numbers        
}

2nd class: // this is where the array to be stored

public class Example2{
    public void Storage{
        int[] NumberStorage = /* this is where the Numbers from the
                                          1st class to be stored */
    }
}
Idos

In your Example class create a getter:

public int[] getNumbers() { return Numbers; }

Then in your Example2 class you can instantiate an instance of Example and call the getter like:

public void storage(){
    Example example = new Example();
    int[] NumberStorage = example.getNumbers();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java, Storing JSON Array to class and calling it from other class

From Dev

How to edit an array from another class in Java

From Dev

Updating an array from another class Java

From Dev

Java: Import array of Strings from another class

From Dev

get an array from another class in java

From Dev

Java: Import array of Strings from another class

From Dev

Making an array object from another Class in Java

From Dev

Storing enum values from another namespace in an array

From Dev

Storing a multidimensional array from another array and calling it in a foreach loop

From Dev

Storing only specific values in an array from another array

From Dev

Storing each sentence in an array from a document in java?

From Dev

Receiving parameter for an array of objects from another class in Java?

From Dev

How to call on something from another class in Java and use it's Array?

From Dev

Java access array from inside another class method

From Dev

Receiving parameter for an array of objects from another class in Java?

From Dev

Java : Is it possible to return an array of Objects from one class to another

From Dev

Storing an unknown function from another class to execute later on itself

From Dev

Java Array Storing Values

From Dev

Storing object into an array - Java

From Dev

Java Array Storing Values

From Dev

Storing object in array in Java

From Dev

Java , storing strings into an array

From Dev

How to extend class from another class (Java)

From Dev

Java storing type information along with Byte[] array from toBytes

From Dev

(java) - Storing each word from an input file in an array of Strings

From Dev

How to access an array from another class

From Dev

Getting Array from Another class C++

From Dev

pass integer array from one class to another

From Dev

Add an element from another class to an array list

Related Related

  1. 1

    Java, Storing JSON Array to class and calling it from other class

  2. 2

    How to edit an array from another class in Java

  3. 3

    Updating an array from another class Java

  4. 4

    Java: Import array of Strings from another class

  5. 5

    get an array from another class in java

  6. 6

    Java: Import array of Strings from another class

  7. 7

    Making an array object from another Class in Java

  8. 8

    Storing enum values from another namespace in an array

  9. 9

    Storing a multidimensional array from another array and calling it in a foreach loop

  10. 10

    Storing only specific values in an array from another array

  11. 11

    Storing each sentence in an array from a document in java?

  12. 12

    Receiving parameter for an array of objects from another class in Java?

  13. 13

    How to call on something from another class in Java and use it's Array?

  14. 14

    Java access array from inside another class method

  15. 15

    Receiving parameter for an array of objects from another class in Java?

  16. 16

    Java : Is it possible to return an array of Objects from one class to another

  17. 17

    Storing an unknown function from another class to execute later on itself

  18. 18

    Java Array Storing Values

  19. 19

    Storing object into an array - Java

  20. 20

    Java Array Storing Values

  21. 21

    Storing object in array in Java

  22. 22

    Java , storing strings into an array

  23. 23

    How to extend class from another class (Java)

  24. 24

    Java storing type information along with Byte[] array from toBytes

  25. 25

    (java) - Storing each word from an input file in an array of Strings

  26. 26

    How to access an array from another class

  27. 27

    Getting Array from Another class C++

  28. 28

    pass integer array from one class to another

  29. 29

    Add an element from another class to an array list

HotTag

Archive