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 */
}
}
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.
Comments