Collections 1). HashMap is an Interface. How we can create an instance to that HashMap? Ans: HashMap is an class which implements the map interface. The H.M doesn’t guarented the order of its elements. Therefore the order in which they have added to a H.M is not necessarly the order in which they are read by an iterator. 2) When we will use ArrayList and HashMap? ArrayList: - 1. Suppose dynamic Arrays that can grow is needed ----- ArrayList can dynamically increase and decrease the size. ---- When size is exceeded the collection is automatically enlarged. When objects are removed the Array may be shrunk. HashMap: - 1. H.M class implements the map interface. 1. The execution time of basic operations such as get() and put() 2. H.M doesn’t guaranteed the order of its elements: HashMap hm=new HashMap (); Hm.put (“LARA”, newString (243546); 3. Based on name it will retrieve the value. 3)
When we use HashMap and HashTable?
HashTable: - H.T is syn., based on requirement, if client don’t need efficiently then we use H.T (because syn. reduces the efficiency) HashMap: - If client want efficiently then we will use H.M(‘cos its not syn.) 4) Difference between HashTable and HashMap? HashTable 1. HashTable is syn 2. HashTable doesn’t accept nulls, based on value retrieve key. HashMap 4. HashMap is not syn. 5. HashMap accepts nulls based, on value retrieve key. 5). what is a set? Set is an interface implements collection interface, to represent a set of unique elements. 6). what is list? List interface implements collection interface, to maintain a sequence of elements which need not be unique. Classes are: array list, vector, linked list. 7Q).What is the difference b/w HashTable and HashMap? Ans:
HashTable 1) Is Synchronous 2) It will not accept Null Values 3) Based on the key it retrieve Value
HashMap is not Synchronous Accept Null Values Based on the key it retrieve Value
8) Diff. b/w array and arraylist () Ans: Array: we have to declare some datatype. Only fixed n.of elements we can store. ArrayList: we can store any type of datatype. Dynamically increase (we can add n.of elements) 9). Diff. b/w Vector and ArrayList Ans: Vector: Synchronous process ArrayList: Non Synchronous. 10).In application server what we will declare ArrayList (or) vector.why? Ans: we will use array list in application server .because application server provide syn process. 11) Which collection is fast?? Ans: ArrayList. Because is not asynchronous. 12). what is static factory??? Ans:: static factory methods from the collections class can b utilized to create decorators that provide thread safety for collection. Collection Synchronized collection (collection c ) List Synchronized List (List list) Map Synchronized Map (Map m) Set Synchronized Set (set s) SortedMap Synchronized SortedMap (SortedMap m) SortedSet Synchronized SortedSet (SortedSet s) 13) Java.util classes sub classes: - Array list, array, HashMap, Hashset, Hashtable(1.0) , linked list, properties(1.0), stacks(1.0),TreeMap, TreeSet, vector(1.0). 14) Java.util interfaces sub classes: - collection, compartor, iteration, list, map, set, sorted set, sortedMap. 15). Diff b\w array &vector? Ans: array: when we want to declare same data type and they are only a fixed no. of elements we can store. Vector we can store any type of data type and the size of vector can dynamically increase (we can add no.of elements and it is a syn.) 16). we have arraylist if we want provide syn what we have to do? Ans: ArrayList list = new ArrayList (); Public static List synchronizedList (list);
17). what are the collections in java? ans; set, list, sorted set, comparator, iterator , map, sorted map Classes are: array list, vector, linked list. 18). What is a set? Set is an interface extends collection interface, to represent a set of unique elements. 20). What is list? List interface extends collection interface, to maintain a sequence of elements which need not be unique.
21) When we use HashMap and HashTable? HashTable :- H.T is syn.based on requirement, if client don’t need efficiently then we use H.T(because syn. Decreased the efficiency) HashMap :- If client want efficiently then we will use H.m(‘cos its not syn.) 22) When we will use ArrayList and HashMap? ArrayList :- 1. Suppose dynamic Arrays that can grow is needed ----- ArrayList can dynamically increase and decrease the size. ---- When size is exceeded the collection is automatically enlarged. When objects are removed the Array may be shrunk. HashMap: - 1. H.M class implements the map interface. 2. The execution time of basic operations such as get() and put() 3. H.M doesn’t guarented the order of its elements: HashMap hm=new HashMap (); Hm.put (“LARA”, newString (243546); 4. Based on name it will retrieve the value. 23). HashMap is an Interface. How we can create an instance to that HashMap ? HashMap is a class which implements the map interface. The H.M doesn’t guarented the order of its elements. Therefore the order in which they have added to a H.M is not necessarly the order in which they are read by an iterator. 24)What is Collection. Ans: collection is
31) What is the difference between Hashmap and Hashtable. (*) 32)What is the difference between Vector, Array and Arraylist. (* 36) What is the difference between List, Set and Map. (*) 40)What is the difference between Iterator and Enumeration 41) What is the difference between Comparable and Comparator. 44) What is the difference between HashMap and TreeMap. (*) 56) What are the various Collection classes available. (*) 58)Which Collection class is used for FIFO in Java. 59) Which Collection class is used for LIFO in Java. 63) Can we add Hashtable/HashMap to a vector.
13. What is the Collections API? The Collections API is a set of classes and interfaces that support operations on Collections of objects. 15. What is the List interface? The List interface provides support for ordered collections of objects. 17. What is the Vector class? The Vector class provides the capability to implement a growable array of objects 19. What is an Iterator interface? The Iterator interface is used to step through the elements of a Collection. 83. What is the Dictionary class? The Dictionary class provides the capability to store key-value pairs. 98. What is the Map interface? The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with Values. 198. What is the List interface? The List interface provides support for ordered collections of objects.