I have a method:
public static ArrayList<Integer>Iterate(int n){
ArrayList<Integer> numbers = new ArrayList<Integer>(n);{
Random rand = new Random();
rand.setSeed(System.currentTimeMillis());
for(int i = 0; i<n; ++i){
Integer r = rand.nextInt() %113;
numbers.add(r);
Collections.sort(numbers);
}}
And I want to use other methods on this Array to find out certain things about the numbers.
But I can't figure out to call the Arraylist in public static void main(String [] args).
I've tried things like:
System.out.println( numbers.methodname);
And things like that, but Eclipse says numbers cannot be resolved to a variable So what's the proper way to call the ArrayList so a method can effect it?
numbersoutside of the methodIterate. As it is now, only the methodIteratehas access to that variable.ArrayList<Integer>in your method. Just returnnumbersin your method and inmaindo something likeArrayList<Integer> list = Iterate(someValue). Then you can call methods onlist.