Category: Core Java
Java Set is a collection of elements (Or objects) that contains no duplicate elements. Java Set is an interface that extends Collection interface. Unlike List, Java Set is NOT an ordered collection, it’s elements does NOT have a particular order. Java Set does NOT provide a control over the position where you . . . Read more
Difference between Comparator and Comparable in Java? Comparator[I] It is present in java.lang package and it contains only one method. [highlight]compareTo()[/highlight];  If we are depending on default natural sorting order then while adding the object into the TreeSet JVM will call compareTo() method. If default natural sorting order not available or . . . Read more
TreeSet in Java and null acceptance in TreeSet? The underlying data structure is the balanced tree. Duplicate objects are not allowed. Insertion order not preserved. Heterogeneous objects are not allowed otherwise we will get runtime exception saying ClassCastException. Null insertion possible (only once). TreeSet Implement Serializable and Cloneable but not . . . Read more
Difference between HashSet and LinkedHashSet? It is the child class of HashSet. A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. Contains unique elements only like HashSet. Provides all optional set operations, and permits null elements. Maintains insertion order. LinkedHashSet doesn’t have its . . . Read more
HashSet in Java and what is FillRatio or LoadFactor? The underlying data-structure is Hashtable. Duplicate objects are not allowed. Insertion order is not preserved and it is based on HashCode of objects. Null insertion is possible (only once). Heterogeneous objects are allowed. Implements serializable and cloneable but not the RandomAccess interface. . . . Read more
Cursors in Java and difference between them? If you want to get object one by one from the collection then we should go for the cursor. There are three types of cursors available in Java. Enumeration Iterator ListIterator Enumeration We can use the enumeration to get objects one by one . . . Read more
Difference between ArrayList and LinkedList in Java? The underlying data structure is double LinkedList. Insertion order is preserved. Duplicate objects are allowed. Heterogeneous object allowed. Null insertion is possible. LinkedList implements Serializable and Cloneable interface but not RandomAccess LinkedList is the best choice if our frequent operation is insertion . . . Read more
Explain ArrayList and difference between ArrayList and Vector? ArrayList is a class, that uses a dynamic array for storing the elements. It extends AbstractList class and implements List interface. The underlying data structure is a Resizable array or growable array. Duplicates are allowed. Insertion order is preserved. Heterogeneous objects are . . . Read more
What is a Collection Framework in Java? If we want to represent a group of an individual object as a single entity then we should go for collection. It contains several classes and interfaces which can be used to represent a group of an individual object as a single entity. You can . . . Read more
What is an Array and difference between array and collection? An array is an index collection of fixed no of homogeneous data elements. The main advantage of arrays is we can represent multiple values by using a single variable so that readability of the code will be improved. Java array is . . . Read more