展开全部
public class ArrayListTest {
public static void main(String[] args) {
/*List<String> l1 = new ArrayList<String>();
l1.add("hello");
l1.add("world");
l1.add("hello");
System.out.println(l1);
System.out.println(l1.get(1));
//循环遍历
for(int i = 0; i < l1.size(); i++){
System.out.println(l1.get(i));
}*/
List<Employee> l2 = new ArrayList<Employee>();
Employee e1 = new Employee(7369, "scott", 800);
Employee e2 = new Employee(1122, "alean", 2000);
Employee e3 = new Employee(1133, "smith", 1000);
Employee e4 = new Employee(1144, "james", 600);
l2.add(e1);
l2.add(e2);
l2.add(e3);
l2.add(e4);
//自然排序
Collections.sort(l2);
for(Employee e: l2){
System.out.println(e.getName() + ": " + e.getEmpno() +":" + e.getSalary());
}
}//给分吧,嘿嘿
追问
好厉害啊!那么怎样才能把它存到文件里面在读取呢
展开全部
List<YourObjectClass> list = new ArrayList<YourObjectClass>();
list.add(YourObject);
list.get(0).yourMethod();
list.add(YourObject);
list.get(0).yourMethod();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |