public Collection getByCondition(String str){
Iterator it = col.iterator();
while(it.hasNext()){
Object obj = it.next();
if(obj.toString().indexOf(str)>0){
}
}
return col;
}
对象toString得到的是什么呀?
public Collection getByCondition(String str){
Iterator it = col.iterator();
while(it.hasNext()){
Object obj = it.next();
if(obj.toString().indexOf(str)>0){
}
}
return col;
}
对象toString得到的是什么呀?
public String toString() {
return getClass().getName() + "@" + Integer.toHexString (hashCode());
}
这是Object的源码
如果你不想 以此方式返回 可以重写 toString()
例:
public class Student{
private String name;
public Student(String str){
this.name=str
}
public String toString(){
return name;
}
public static void main(String[] args) {
Student test =new Student("test");
System.out.println(test.toString());
}
}
执行结果:test