Java: Avoid inserting duplicate in arraylist

后端 未结 6 1459
太阳男子
太阳男子 2020-11-29 08:56

I am novice to java. I have an ArrayList and I want to avoid duplicates on insertion. My ArrayList is

ArrayList karList         


        
6条回答
  •  没有蜡笔的小新
    2020-11-29 09:08

    You can use LinkedHashSet, to avoid duplicated elements and keep the insertion order.

    http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashSet.html

提交回复
热议问题