How to remove duplicates of a LinkedList ?
This is one of the most frequently asked java question in oracle interview. There can be n number of ways to do the task, below program demonstrates a simple way of doing this.
This is one of the most frequently asked java question in oracle interview. There can be n number of ways to do the task, below program demonstrates a simple way of doing this.
import java.util.*; class RemoveLinkedListDuplicate { public static void removeDuplicate() { LinkedList l=new LinkedList(); l.add("J"); l.add("A"); l.add("V"); l.add("A"); l.add("J"); l.add("A"); l.add("V"); l.add("A"); System.out.println(l); LinkedHashSet lhs=new LinkedHashSet(l); LinkedList ll=new LinkedList(lhs); System.out.println(ll); } public static void main(String[] args) { removeDuplicate(); } }
Output of the Above example :
No comments:
Post a Comment