Collection Framework in Java

Removing Duplicates Array Java

Removing Duplicates Array Java Summary: Java is so developed by Designers to write code easily for Developers. Forget the laborious days of C/C++ coding. This tutorial "Removing Duplicates Array Java" is the place to prove it. It is a general and interesting code for beginners and this can be achieved…

Remove Duplicate Elements in ArrayList

It is a general and interesting code for beginners and this can be achieved in many ways in Java. This code, I would like to keep the code as simple as possible without using any methods and without using any laborious loops of C/C++. Here, I use only constructors but…

Java Made Simple: What is Vector Java with Example?

Sometimes, a data structure is preferred rather than an array in that data structure is growable and accepts dissimilar elements. Being growable dynamically, Vector is preferred when the number of elements to be added are not known earlier in advance or required to change the number of elements (modify the…

List Interface Java

Being a sub interface of Collection inteface, List Interface utilizes all the methods of Collection interface. List Interface accepts duplicate elements. List interface comes with operations like: To manipulate elements by their numerical position in the list with the methods such as remove(), set(), add(), addAll() and get(). To retrieve…

HashSet vs TreeSet

Three most used implementations of Set interface are HashSet, TreeSet and LinkedHashSet. For a novice, it looks difficult to understand. When a list of differences is presented all at a single place, it is easier to understand. Start reading HashSet vs TreeSet Programs are available at HashSet Tutorial and TreeSet…

Collections Comparisons

You must be very strong in Java DS to write comparisons between various Collection classes. This tutorial gives you possible Java DS comparisons. Enumeration vs Iterator Iterator vs ListIterator Vector vs ArrayList Array vs ArrayList for vs foreach Hashtable vs HashMap Set vs HashSet Map vs HashMap HashMap vs TreeMap…

List Iterator Java

In Java, Data structures, known as collection classes or collections framework, is a big topic as it involves many many classes. Choosing a right data structure, in Java, requires good experience and once chosen, writing part, a novice can do. DS is simple in Java because of no pointers. In…

HashSet vs HashMap

Given in simple terms with example codes in respective links. Start reading Differences between HashSet and HashMap. Both look something same but are very different in each respect. Following tables give you both differences and similarities. Two programs are given on HashSet and HashMap. Both belong to Collections framework. One…

ArrayList vs LinkedList

There comes two classes ArrayList and LinkedList to store objects. Internally, ArrayList stores elements as an array form and LinkedList stores elements in node form. Due to their internal style of storing the elements, they come with different performance heads depending the nature of action performed like addition and retrieval.…

Array to List Java

Here we use asList() method of class Arrays. Following is the method signature static List asList(T array): The method returns a List object with all the elements of the array. The list returned is fixed size. That is, you cannot add further elements to the list. Following example on "Array…

List to Array Java

Here, toArray() method of Collections interface is used. This method returns an Object array containing the elements of collection class. Example on on "List to Array Java" explains the usage of toArray() method to convert List to array.

Output screen on List to Array Java

A List object…

Remove Common Elements Two Lists Java

It may be required sometimes to remove common elements two lists Java. Following is the code. ArrayList al1 contains 10, 20 and 30 and ArrayList al2 contains 20, 30, and 50. It is required from al1 to remove 20 and 30 as they are also present in al2. After removal,…

List Extract Common Elements Java

It may be required sometimes to extract the common elements of two lists in Java. Given in simple terms in this tutorial List Extract Common Elements Java. Following code on List Extract Common Elements Java illustrates.

Output screenshot on List Extract Common Elements Java Here we use retainAll() method…

HashMap vs TreeMap

After knowing Hashtable vs HashMap, now let us see the comparison of HashMap with TreeMap. Basically both are derived from Map interface and meant to store key/value pairs. But TreeMap inherits one more interface SortedMap and for this reason it attains the property of returning the elements in sorting order…