Remove LinkedHashSet elements

We can use remove() method of LinkedHashSet to remove elements from LinkedHashSet collection boolean remove(Object obj) Example import java.util.*; public class LinkedHashSetRemoveExample { public static void main(String args[]) {   LinkedHashSet lhs = new LinkedHashSet();   lhs.add(“java”); lhs.add(“c”); lhs.add(“c++”); System.out.println(“LinkedHashSet before removing elements”); System.out.println(lhs); lhs.remove(“java”); System.out.println(“LinkedHashSet after removing elements”); System.out.println(lhs); } } import java.util.*; public […]

Share this article on

Add elements in LinkedHashSet

We can use add() method of LinkedHashSet to add elements to LinkedHashSet collection boolean add(Object obj) It adds the element obj to the Set. Example import java.util.*; public class LinkedHashSetAddExample { public static void main(String args[]) {   LinkedHashSet<String> lhs = new LinkedHashSet<String>();   lhs.add("java"); lhs.add("c"); lhs.add("c++"); System.out.println(lhs); } } import java.util.*; public class LinkedHashSetAddExample […]

Share this article on
< Previous Next >