forked from amit4alljava/AdvJava12W
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63fcde9
commit a5ebba8
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.util.HashMap; | ||
import java.util.TreeSet; | ||
|
||
|
||
public class MapDemo { | ||
|
||
public static void main(String[] args) { | ||
HashMap<String,Object> map = new HashMap<>(); | ||
TreeSet<Integer> amitPhones = new TreeSet<>(); | ||
amitPhones.add(2222); | ||
amitPhones.add(2222); | ||
amitPhones.add(3333); | ||
map.put("amit", amitPhones); | ||
//map.put("amit",3333); | ||
map.put("ram", 3333); | ||
System.out.println(map.get("amit")); | ||
System.out.println(map); | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.util.HashSet; | ||
|
||
class Customer | ||
{ | ||
int id; | ||
String name; | ||
Customer(int id , String name){ | ||
this.id = id ; | ||
this.name = name; | ||
} | ||
public String toString(){ | ||
return "Id "+id +" Name "+name; | ||
} | ||
|
||
public boolean equals(Object o){ | ||
Customer c = (Customer) o; | ||
if(this.id==c.id && this.name.equals(c.name)){ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode(){ | ||
return name.length(); | ||
} | ||
} | ||
public class SetDemo { | ||
|
||
public static void main(String[] args) { | ||
Customer ram = new Customer(1001,"Ram"); | ||
HashSet<Customer> hashSet = new HashSet<>(); | ||
hashSet.add(ram); | ||
Customer ram2 = new Customer(1001,"Ram"); | ||
hashSet.add(ram2); | ||
System.out.println("Ram HashCode "+ram.hashCode()); | ||
System.out.println("Ram2 HashCode "+ram2.hashCode()); | ||
System.out.println(hashSet); | ||
|
||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.HashSet; | ||
|
||
|
||
public class SimpleSet { | ||
|
||
public static void main(String[] args) { | ||
HashSet<String> hs = new HashSet<String>(); | ||
hs.add("mike"); | ||
hs.add("tim"); | ||
hs.add("mike"); | ||
hs.add("tim"); | ||
System.out.println(hs); | ||
} | ||
|
||
} |