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?

Recommended Answers

All 2 Replies

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;
}

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.