Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2a071a7

Browse files
Create HashMapTest.java
1 parent 6b795e4 commit 2a071a7

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

‎Collections/HashMapTest.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//Version 11.1
2+
3+
import java.util.*;
4+
5+
class Student
6+
{
7+
int rollno , marks;
8+
Student(int r,int m)
9+
{
10+
rollno=r;
11+
marks=m;
12+
}
13+
public String toString()
14+
{
15+
return(rollno+" : "+marks);
16+
}
17+
public int hashCode()
18+
{
19+
return(rollno);
20+
}
21+
public boolean equals(Object ob)
22+
{
23+
Student st=(Student)ob;
24+
return(rollno == st.rollno);
25+
}
26+
}
27+
class HashMapTest
28+
{
29+
public static void main(String s[])
30+
{
31+
HashMap hm=new HashMap();
32+
hm.put(new Student(101,80),"abc");
33+
hm.put(new Student(102,75),"xyz");
34+
hm.put(new Student(103,85),"pqr");
35+
hm.put(new Student(101,55),"hij");
36+
37+
Set st=hm.keySet();
38+
Iterator itr=st.iterator();
39+
while(itr.hasNext())
40+
{
41+
Student key=(Student)itr.next();
42+
String value=(String)hm.get(key);
43+
System.out.println(key+" : "+value);
44+
}
45+
}
46+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /