How to remove duplicate elements from ArrayList in Java Many times we need to remove duplicate or repetitive elements from the ArrayList because ArrayList dont check for duplicates. We will use HashSet to remove duplicates from the ArrayList. As we all know HashSet do not store duplicates but it also do not maintain the order […]Continue Reading →
5 interview questions and answers on HashMap in Java. HashMap is one of the widely used type of Collection in Java. So it is very important to know some of the key things in HashMap such as How HashMap works, HashMap get() and put() methods, HashMap size etc. Lets see some of the interview questions […]Continue Reading →
How HashMap works in Java How HashMap works in Java or do you know Hashmap in java is one of the most asked interview question in java. It checks your knowledge about the collection as HashMap is one of the mostly used Collection class. Also I would like to mention another favorite interview question which is […]Continue Reading →
What is the difference between ArrayList and vector in java? This is one of the favorite interview question and very important to know the difference between the two because we need to use lot of those collection while writing the code. So it is essential to understand the differences between ArrayList and Vector for its […]Continue Reading →
This post explains implementation of Hashtable. We can find this class in java.util. Hashtable maps keys to values , these keys and values can be any non null objects. Hashtable uses hashing function algorithm so the object which we use for key must implement equals and hashcode methods. Initial capacity and the load factor are […]Continue Reading →
We can use Iterator to list the elements in java. We can use Iterator’s hasNext() and next() methods to list the elements in Collection. hasNext() method is used to check the whether collection contains any more elements, so we can use this to get the highest boundry of collection list. next() method returns next element […]Continue Reading →
As the name suggest this (hidden or not so famous) feature allows initialization in java in short cut way. Now lets look how double brace initialization works. Lets first consider the normal initialization way , suppose we are initializing the ArrayList we do something like following : List fruits = new ArrayList(); fruits.add( “apple” ); […]Continue Reading →
Comparable This interface comes from the java.lang package. When a class implements this interface , the class imposes a natual order for itself and comparison scheme with the method compareTo. List of objects which implements this interface are automatically gets sorted using Collections.sort method i.e. These objects become comparable e.g. Sorting of an arraylist of […]Continue Reading →
How to use TreeSet in Java : TreeSet in java is a class which implements Set interface. Let see few characteristics of TreeSet in java before taking look at java treeset example. TreeSet in java 1. TreeSet in java guarantees sorted set of elements which are arranged in ascending order. 2. TreeSet in java provides […]Continue Reading →
HashSet : HashSet implements Set interface. To store the values it uses Hashtable internally which uses hashing mechanism. Because of Hashing there are two advantages, first because it is used to find duplicates using the key and second is it gives constant time performance for operations such as add, remove, contains etc. Lets look at […]Continue Reading →
You may want to read it!
- Simple JTable example using AbstractTableModel
- How to show DialogBox in java? Complete JOptionPane tutorial.
- how to use CSS style or stylesheet in java swing JEditorPane ?
- Enum in java with java enum examples
- How to display custom objects in JList using ListCellRenderer?
- How to print message , stacktrace of Exception in java?
- How to disable JList selection in java?
- How to sort arraylist containing objects?
- GridBagLayout tutorial and example
- How to set size of PDF file using iText?