-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHashSet.java
More file actions
30 lines (28 loc) · 891 Bytes
/
HashSet.java
File metadata and controls
30 lines (28 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// Now list can contain the duplicate element but set contains only unique element
HashSet<String> hm=new HashSet<String>();
hm.add("Niraj");
hm.add("pankaj");
hm.add("hello");
hm.add("world");
Iterator itr=hm.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
System.out.println(" ");
// to copy the set content in the LinkedList and then we can use the listiterator to reverse
LinkedList<String> ll=new LinkedList<String>(hm);
ListIterator<String> litr=ll.listIterator();
while(litr.hasPrevious()){
System.out.println(litr.previous());
}
}
}