0

Let's say I have a method called 'test' which should return the arraylist called 'theList' containing X number of Integers.
How would I do that?

public static void test(){
    SOME CODE
    ...
    return theList
}

What should 'void' and 'theList' be replaced with in that code to make it work?

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by efth
1

It would be declared as follows...

public static ArrayList<A_CLASS_NAME> test() {
  // instantiate an empty array list of A_CLASS_NAME
  ArrayList<A_CLASS_NAME> theList = new ArrayList<A_CLASS_NAME>();
  ...
  return theList;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.