There are many ways to do it. Some of them are:
- Using iterative approach
- Using HashSet (but does not maintain insertion order)
- Using LinkedHashMap
Program:
When you run above program, you will get following output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Removing duplicates from list:
Using iterative approach:
John
Ankit
Rohan
Amit
*******************************
Using HashSet :
Rohan
Ankit
Amit
John
*******************************
Using LinkedHashSet :
John
Ankit
Rohan
Amit
|