asked 234k views
0 votes
The _____ method returns a range of objects from the ArrayList as another ArrayList?

1) getRange()
2) subList()
3) rangeList()
4) getSubRange()

1 Answer

5 votes

Final answer:

The subList() method returns a range of objects from the ArrayList as another ArrayList. It takes the starting index (inclusive) and the ending index (exclusive) as parameters.

Step-by-step explanation:

The subList() method returns a range of objects from the ArrayList as another ArrayList. This method takes two parameters, the starting index (inclusive) and the ending index (exclusive) of the range you want to retrieve. Here's an example:

ArrayList<String> myArrayList = new ArrayList<>();
myArrayList.add("apple");
myArrayList.add("banana");
myArrayList.add("cherry");
myArrayList.add("date");

ArrayList<String> subArrayList = new ArrayList<>(myArrayList.subList(1, 3));
System.out.println(subArrayList); // Output: [banana, cherry]

answered
User Rafa Gomez
by
8.2k points