0

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 */
    }
}
2
  • 1
    Please don't start variables and methods with capital letters or anything else but classes Commented Feb 27, 2016 at 14:27
  • NoobProgramer if an answer has solved your question please accept it. Thank you Commented Mar 1, 2016 at 10:12

2 Answers 2

4

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();
}
Sign up to request clarification or add additional context in comments.

Comments

0

This might be what You want

First Class public class Class1{

private int [] Array = { 1,2,3,2,3,4};

public  Class1(){


   Class2 a =  new Class2();

   a.Class2(Array,6);
 }}

second class public class Class2 { public void A( Array, size) //enter Sort here } }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.