I have one class with a method like this:
public ArrayList<Integer> myNumbers() {
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers.add(5);
numbers.add(11);
numbers.add(3);
return(numbers);
}
how can i call this method inside another class?
1. If that class from which you want to call this method, is in the same package, then create an instance of this class and call the method.
2. Use
Composition3. It would be better to have a
Generic ArrayListlikeArrayList<Integer>etc…eg: