What sequence of digits will the following program print?
import java.util.* ; public class Main{ public static void main (String args []){ List s1 = new ArrayList ( ); s1.add ("a"); s1.add ("b"); s1.add (1, "c"); List s2 = new ArrayList ( s1.subList (1, 1) ); s1.addAll (s2); /*w w w. j a v a2s . c om*/ System .out.println (s1); } }
Select 1 option
Correct Option is : D
First, "a" and "b" are appended to an empty list.
Next, "c" is added between "1" and "2".
A new list s2 is created using the sublist view allowing access to elements from index 1 to index 1(exclusive) (i.e. no elements ).
Now, s2 is added to s1.
So s1 remains:a, c, b