Thread: Unique List

Forum : Collections   10 Feb, 2018 11:10
User Image
Suneel

Newbie

Joined: 12 Jun, 2017

Points: 105

Threads: 8

Posts: 16

Unique List

| Quote Date : 10 Feb, 2018    Views:516    

How to create List with Unique Elemnts?

Comments

User Image
Amritk

Newbie

Joined : 8 May, 2017

Points : 230

Threads: 57

Posts: 216

Re: Unique List

Reply Date : 12 Feb, 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 : 2 Jul, 2017

Points : 100

Threads: 0

Posts: 10

Re: Unique List

Reply Date : 10 Feb, 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