Technical Interview Questions and Answers :: Java
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();
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
No Discussion on this question yet!
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.
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.
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).
An immutable object cannot be modified after it has been created. Also can be said unchangeabe object.
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.
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.
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