Thread: Unique List

Forum : Collections   10-2-2018 06:10:50 AM
User Image
Suneel

Newbie

Joined: Jun 12, 2017

Points: 105

Threads: 8

Posts: 16

Unique List

| Quote Date : Feb 10, 2018    Views:421    

How to create List with Unique Elemnts?

Comments

User Image
Amritk

Newbie

Joined : May 8, 2017

Points : 230

Threads: 57

Posts: 211

Re: Unique List

Reply Date : Feb 12, 2018

We can do this by using generic. Like
List<Integer> list=new ArrayList<Integer>();

now we can add only integer type value.

But if you are looking for unique value means no duplicate value then we need to write some logic.


User Image
Bheema

Newbie

Joined : Jul 2, 2017

Points : 100

Threads: 0

Posts: 10

Re: Unique List

Reply Date : Feb 10, 2018

using generics we can create List with Unique elements from java 1.5 version on wards.
eg:
List<String> values = new ArrayList();
list.add("SJG");
list.add(20);// it will not allowed only allowed values are String only.

Load More

No More Comments