62,614
社区成员
发帖
与我相关
我的任务
分享
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exp1;
/**
*
* @author 波
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Demo {
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("Schmidt", "+49 6227 48597");
hashMap.put("Mayer", "+49 6221 1808");
hashMap.put("Schmidt", "+49 40 364850");
hashMap.put("Treusch", "+49 89 98965456");
Set keys = hashMap.keySet();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = (String) hashMap.get(key);
System.out.println("key: " + key + "\tvalue: " + value);
}
TreeSet tree = new TreeSet();
tree.add(new Demo().new Customer("Schmidt", 48597));
tree.add(new Demo().new Customer("Mayer", 180));
tree.add(new Demo().new Customer("Schmidt", 3648));
Iterator iter2 = tree.iterator();
while (iter2.hasNext()) {
Customer customer = (Customer) iter2.next();
System.out.println(customer.getName());
}
}
public class Customer implements Comparable {
private String name;
private int id;
public Customer(String name, int id) {
this.name = name;
this.id = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int compareTo(Object otherCustomer) {
return this.id = ((Customer) otherCustomer).getId();
}
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Demo {
public static void main(String[] args){
HashMap hashMap=new HashMap();
hashMap.put("Schmidt","+49 6227 48597");
hashMap.put("Mayer","+49 6221 1808");
hashMap.put("Schmidt","+49 40 364850");
hashMap.put("Treusch","+49 89 98965456");
Set keys= hashMap.keySet();
Iterator iter=keys.iterator();
while (iter.hasNext()){
String key=(String) iter.next();
String value=(String) hashMap.get(key);
System.out.println("key: "+key+"\tvalue: "+value);
}
TreeSet treeSet=new TreeSet();
treeSet.add(new Demo().new Customer("Schmidt",48597));
treeSet.add(new Demo().new Customer("Mayer",180));
treeSet.add(new Demo().new Customer("Schmidt",3648));
Iterator iter2=treeSet.iterator();
while (iter2.hasNext()){
Customer customer=(Customer)iter2.next();
System.out.println(customer.getName());
}
}
class Customer implements Comparable{
private String name;
private int id;
public Customer(String name, int id){
this.name=name;
this.id=id;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public int compareTo(Object otherCustomer){
return this.id=((Customer)otherCustomer).getId();
}
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Demo {
public static void main(String[] args){
HashMap hashMap=new HashMap();
hashMap.put("Schmidt","+49 6227 48597");
hashMap.put("Mayer","+49 6221 1808");
hashMap.put("Schmidt","+49 40 364850");
hashMap.put("Treusch","+49 89 98965456");
Set keys= hashMap.keySet();
Iterator iter=keys.iterator();
while (iter.hasNext()){
String key=(String) iter.next();
String value=(String) hashMap.get(key);
System.out.println("key: "+key+"\tvalue: "+value);
}
TreeSet treeSet=new TreeSet();
treeSet.add(new Customer("Schmidt",48597));
treeSet.add(new Customer("Mayer",180));
treeSet.add(new Customer("Schmidt",3648));
Iterator iter2=treeSet.iterator();
while (iter2.hasNext()){
Customer customer=(Customer)iter2.next();
System.out.println(customer.getName());
}
}
}
class Customer implements Comparable{
private String name;
private int id;
public Customer(String name, int id){
this.name=name;
this.id=id;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public int compareTo(Object otherCustomer){
return this.id=((Customer)otherCustomer).getId();
}
}