1.What Is the use of Collections Framework?
Reduces programming effort,Increases program speed and quality,Allows interoperability among unrelated APIs,Reduces effort to learn and to use new APIs,Reduces effort to design new APIs,Fosters software reuse.
2.Difference between List,Set and Map?
List can contain duplicate elements whereas Set contains only unique elements.Map contains key and values both.
3.What is the difference between collection and Collections?
Collection is an interface whereas Collections is a class. Collection interface provides normal functionality of data structure to List, Set and Queue. But, Collections class is to sort and synchronize collection elements.
4.Use of Arrays class in collections framework?
5.What is the difference between ArrayList and Vector?
A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent. As the documentation says, a Vector and an ArrayList are almost equivalent. The difference is that access to a Vector is synchronized, whereas access to an ArrayList is not
6.What is the difference between ArrayList and LinkedList?
ArrayList
1) ArrayList internally uses dynamic array to store the elements.
2) Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory.
7.What is the difference between HashSet|TreeSet|LinkedHashSet?
8.What is the difference between HashSet|TreeMap|LinkedHashSet?
HashMap
1) HashMap is non synchronized. It is not-thread safe and can't be shared between many threads without proper synchronization code.
2) HashMap allows one null key and multiple null values.
3) HashMap is a new class introduced in JDK 1.2.
4) HashMap is fast.
5) We can make the HashMap as synchronized by calling this code Map m = Collections.synchronizedMap(hashMap);
6) HashMap is traversed by Iterator.
7) Iterator in HashMap is fail-fast.
8) HashMap inherits AbstractMap class.
Hashtable
1) Hashtable is synchronized. It is thread-safe and can be shared with many threads.
2) Hashtable doesn't allow any null key or value.
3) HasHashtable is slow.htable is a legacy class.
4) Hashtable is internally synchronized and can't be unsynchronized.
5) Hashtable is traversed by Enumerator and Iterator.
6) Enumerator in Hashtable is not fail-fast.
7) Hashtable inherits Dictionary class.
10.What is the advantage of properties file?
If you change the value in properties file, you don't need to recompile the java class. So, it makes the application easy to manage.
11.What are legacy classes?
12.which collection is used to store unique value?
13.How to sort elements in an ArrayList without removing duplicate value?
14.How to sort and remove duplicate elemnts in an ArrayList?
15.What is the difference between iterator and Listiterator?
16.What is the difference between iterator and Enumeration?
17.What is the difference between comparable and comparator?
18.What is the advantage of generic collection?
If we use generic class, we don't need typecasting. It is type safe and checked at compile time.
19.How to synchronize list,set,and Map elements?
public static List synchronizedList(List l){},
public static Set synchronizedSet(Set s){},
public static SortedSet synchronizedSortedSet(SortedSet s){},
public static Map synchronizedMap(Map m){},
public static SortedMap synchronizedSortedMap(SortedMap m){}
20.What is the Dictionary class?
The Dictionary class provides the capability to store key-value pairs.