Java OCA OCP Practice Question 2630

Question

Consider the following program:

import java.util.*;
import java.util.concurrent.*;

public class Main {
        public static void main(String []args) {
                List list = Arrays.asList(10, 5, 10, 20);
                System.out.println(list);
                System.out.println(new HashSet(list));
                System.out.println(new TreeSet(list));
                System.out.println(new ConcurrentSkipListSet(list));
        }/*from www . j a v a  2s. co  m*/
}

This program prints the following:

a)[10, 5, 10, 20]/*from  w w w. j  a va2  s  . c o  m*/
  [20, 5, 10]
  [5, 10, 20]
  [5, 10, 20]

b)[10, 5, 10, 20]
  [5, 10, 20]
  [5, 10, 20]
  [20, 5, 10]

c)[5, 10, 20]
  [5, 10, 20]
  [5, 10, 20]
  [5, 10, 20]

d)[10, 5, 10, 20]
  [20, 5, 10]
  [5, 10, 20]
  [20, 5, 10]


a)

Note

Lists are unsorted.

HashSet values are unsorted and retain unique elements.

TreeSet values are sorted and retain unique elements.

ConcurrentSkipListSets are sorted and retain unique elements.




PreviousNext

Related