package testSortAlgorithm;
import java.util.ArrayList;
import java.util.List;
public class ListLike {
// 定义员工类
public class EmployeeBean {
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public List list = new ArrayList();
// 增加员工
public List addList(String name, int age) {
EmployeeBean employee1 = new EmployeeBean();
employee1.setName(name);
employee1.setAge(age);
list.add(employee1);
return list;
}
// 显示所有员工
public void ShowList() {
for (int i = 0; i < list.size(); i++) {
System.out.println(((EmployeeBean) (list.get(i))).getName() + " "
+ ((EmployeeBean) (list.get(i))).getAge());
}
}
// 模糊查询
public List likeString(String likename) {
for (int i = 0; i < list.size(); i++) {
if (((EmployeeBean) (list.get(i))).getName().indexOf(likename) <= -1)
list.remove(i);
}
return list;
}
public static void main(String arg[]) {
ListLike ll = new ListLike();
ll.addList("wuxiao", 13);
ll.addList("wangwang", 11);
ll.addList("wanghua", 12);
ll.addList("xiaowang", 13);
ll.addList("xiaoxiao", 13);
ll.likeString("w");
ll.ShowList();
}
}