Java LinkedList

Posted by Hayri Cicek on September 18, 2019

Java LinkedList is a linear data structure, which means the elements are linked using pointers.
LinkedList can have duplicate and null values and maintains insertion order.
The LinkedList can be used as a List, Queue or Stack because the LinkedList class implements List and Deque interfaces.


Read More →

Java TreeSet

Posted by Hayri Cicek on September 16, 2019

TreeSet can not contain null values and are slower than HashSet.
TreeSet contains only unique values and elements are sorted in ascending order.


Read More →

Java TreeMap

Posted by Hayri Cicek on September 14, 2019

Java TreeMap implements the Java Map interface and the key/value pairs in a TreeMap will be sorted in an ascending key order. In the following example, we create a TreeMap and adding some elements to it.


import java.util.TreeMap;

public class AddingElementsTreeMap {
    public static void main(String[] args) {
        TreeMap<Integer,String> cities = new TreeMap<>();
        
        cities.put(1, "Helsingborg");
        cities.put(5, "Stockholm");
        cities.put(3, "Göteborg");
        cities.put(2, "Malmö");
        cities.put(4, "Uppsala");

        System.out.println("Cities : "   cities);
    }
}



Read More →

Java HashMap

Posted by Hayri Cicek on September 12, 2019

Java HashMap implements Map interface and is used for storing items in key/value pairs, and you access a value by its key, and HashMap keys must be unique.
HashMap can have null value and null key.


Read More →

Java HashSet

Posted by Hayri Cicek on September 11, 2019

Java HashSet is a collection that contains unique elements and implements the Set interface.
The following example shows how to create a HashSet and add new elements using the add() method.


import java.util.HashSet;

public class HashSetAddElementsExample {
    public static void main(String[] args) {
        HashSet<String> cities = new HashSet<>();

        cities.add("Helsingborg");
        cities.add("Malmö");
        cities.add("Stockholm");
        cities.add("Göteborg");
        cities.add("Helsingborg");
        
        System.out.println("Cities : "   cities);
    }
}



Read More →

Java ArrayList

Posted by Hayri Cicek on September 10, 2019

Java ArrayList are dynamic arrays that can grow as needed not like standard Java arrays which are fixed length. The following statement will create an ArrayList.


ArrayList<Integer> numbers = new ArrayList<>();


Read More →