Given:
import java.util.*; public class Main { public static void main(String[] args) { ArrayList<String> myList = new ArrayList<String>(); myList.add("apple"); myList.add("carrot"); myList.add("banana"); myList.add(1, "plum"); System.out.print(myList);/*from w ww .j av a 2s . c om*/ } }
What is the result?
B is correct.
ArrayList elements are automatically inserted in the order of entry.
They are not automatically sorted.
ArrayLists use zero-based indexes.
The last add()
inserts a new element and shifts the remaining elements back.