list allows duplicates but how to write logic to dis-allow duplicates in list in core java -


list allows duplicates write logic dis-allow duplicates in list

import  java.util.*; class altest {     public static void main(string[] args) {         arraylist al=new arraylist();         al.add("a");         al.add("b");         al.add("a");         al.add(10);         al.add(20);         al.add("list");         system.out.println(al);     } } 

here duplicated should not duplicate

the easiest way use linkdhashset instead. prevent duplicates, , can still iterate on elements in same order added set.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -