Java LinkedHashSet - Smart Tech Guides

Latest

Hi this is Sravan Kumar from India. SMART TECH GUIDES is a technical blog. it helps you to learn about Java topics, frameworks and tools like Jenkins, GitHub & related explanations, data base related topics. All these Explanations are explained in simple and understandable manner.

Subscribe Us

SMART TECH GUIDES

Java LinkedHashSet

 

LinkedHashSet:

The LinkedHash Set is part of collection framework and it is available in “java.util” package.

LinkedHashSet Implements Set, Cloneable, Serializable interfaces and extends HashSet class.

LinkedHashSet similar to HashSet class. but it maintains the insertion order.

LinkedHashSet contains unique elements.

LinkedHashSet uses a hash table & doubly linked list to store & maintain the elements.

LinkedHashSet allows one null value.

LinkedHashSet is non-synchronized.


Creation of LinkedHashSet:

LinkedHashSet <E> hs = new LinkedHashSet <E>();

LinkedHashSet <E> hs = new LinkedHashSet <E>(int capacity);



Java Code:


package com.smarttechguides;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet;
public class Account {
public static void main(String[] args) throws IOException {
LinkedHashSet<String> CustomerName = new LinkedHashSet<String>();
CustomerName.add("venkat");
CustomerName.add("Abhilash");
CustomerName.add("Imran");
CustomerName.add("Joy");
CustomerName.add("Joy");
CustomerName.add(null);
// CustomerName.add(null);
Iterator<String> iterator = CustomerName.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
view raw Account.java hosted with ❤ by GitHub
Output:
venkat
Abhilash
Imran
Joy
null
view raw javaw.exe hosted with ❤ by GitHub

No comments:

Post a Comment