java,ArrayList类的应用
1、以对象属性在对象集合中查找对象
import java.util.ArrayList;
/**
* java,ArrayList集合 以对象属性在对象集合中查找对象
*/
public class test {
int i;
String s;
public test(int i, String s) {
this.i = i;
this.s = s;
}
public String toString() {
return "test{" +
"i=" + i +
", s='" + s + '\'' +
'}';
}
public static void main(String[] args) {
ArrayList<test> list=new ArrayList();
test t1=new test(0,"123");
test t2=new test(1,"456");
list.add(t1);
list.add(t2);
int a;
for ( a=0;a<list.size();a++)
{
test t= list.get(a);
if (t.s.equals("123"))
System.out.println(t.toString());
}
}