Technical Interview Questions and Answers :: Java
11 / 66
Iterator allows to traverse the collection and also it has methods which enables to obatin or remove elements. ListIterator adds the feature of traversing the list bi-directionally, also modify the elememts.
Eg.: Iterator itr = al.iterator();
while(itr.hasNext()) {}
12 / 66
List is subinterface of collection interface
List is objects can be stored in sequencelly order
List objects can be stored in index or access by its index
List is preserve the order of insertion.
List duplicate objects can be stored and also null insertion is allowed.
list is 3 implemention classes
1.ArrayList Class
2.LinkedList Class
3.Vector Class
13 / 66
arrays store only primitive type values and arraylist store primitive type
14 / 66
A set is a collection that cannot contain duplicate elements. Set has it's implementation in various classes like HastSet, TreeSet, LinkedHashSet. Set has only methods that are inherited from Collection and adds the restrictions to prohibit duplicate elements.
15 / 66
Map contains values on the bais of keys.
Keys= value key.
These keys are known as entry.
HasMap classes implements the Map interface by using Hash Table.
16 / 66
Java Comparable interface is used to order the objects of user-defined classes. It has compareTo(object) method and is available in jva.lang package.
Java Comparator interface is available in java.util package. It has two methods compare(Object obj1, Object obj2) and equals(Object element).
17 / 66
An immutable object cannot be modified after it has been created. Also can be said unchangeabe object.
18 / 66
When 'new String()' is used, it creates a new string object in the heap memory and as when literal is used, it may return an existing object from the string pool, it exists else creates a new object.
19 / 66
StringBuffer has same objects as StringBuilder, but each method in StringBuffer is synchronized,i.e., it's thread safe. That's why StringBuilder is faster than StringBuffer.
20 / 66
Singleton class is a design pattern where it allowes creating only one object per class
we should define constructor as private it object creation is restricted
we should use static method this method is returen object of same class only