Java?????? Map?????
???????????? ???????[ 2013/12/19 11:32:05 ] ????????
???????????
???????????????<>??????????????????????????
?????????java?????????????????÷??????
???????????????д???????????<>????巺???
???????<>????????????????????ü??????
??????????????洢??????????????????????<>?м??ɡ?
???????
import java.util.*;
class TreeSetTest{
public static void main(String[] args){
TreeSet<String> ts = new TreeSet<String>(new LenComparator());
ts.add("abcd");
ts.add("cc");
ts.add("cba");
ts.add("z");
ts.add("a");
ts.add("sdcvrt");
Iterator<String> it = ts.iterator();
while(it.hasNext()){
String s = it.next();
System.out.println(s);
}
}
}
//??????????????Comparator??????÷???
class LenComparator implements Comparator<String> {
public int compare(String s1??String s2){
/*
//????
int num = new Integer(s1.length()).compareTo(new Integer(s2.length()));
if(num==0)
return s1.compareTo(s2);
return num;
*/
//????
int num = new Integer(s2.length()).compareTo(new Integer(s1.length()));
if(num==0)
return s2.compareTo(s1);
return num;
}
}
/*
???
sdcvrt
abcd
cba
cc
z
a
*/
|
??????????
??????????巺????
??????????????????????????????????????
???????????Object??????????
??????????巺?????????
class Worker{}
class Student{}
//?????????????
class Tool{
private Object obj;
public void setObject(Object obj){
this.obj = obj;
}
public Object getObject(){
return obj;
}
}
//??????
class Utils<QQ>{
private QQ q;
public void setObject(QQ q){
this.q = q;
}
public QQ getObject(){
return q;
}
}
class GenericDemo{
public static void main(String[] args){
Utils<Worker> u = new Utils<Worker>();
u.setObject(new Worker());
Worker w = u.getObject();
/*
Tool t = new Tool();
t.setObject(new Worker());
Worker w = (Worker)t.getObject();
*/
}
}
|
???????????
????????ò?????????????????????????????????????????????
???????????????????
class Demo{
//??????????????
public <T> void show(T t){
System.out.println("show:"+t);
}
public <Q> void print(Q q){
System.out.println("print:"+q);
}
}
class GenericDemo{
public static void main(String[] args){
Demo d = new Demo();
d.show(5);
d.show(new Integer(5));
d.show("haha");
d.print(8);
d.print(new Integer(5));
d.print("heihei");
}
}
/*
???
show:5
show:5
show:haha
print:8
print:5
print:heihei
*/
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11