码迷,mamicode.com
首页 > 其他好文 > 详细

大数据第10天

时间:2016-04-13 21:12:03      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:list

1、remove(int index);//删除指定位置的元素



2、remove(Object o);//删除指定对象,考查删除对象的规则是什么?

3、removeAll(Collection col);//删除指定集合中的所有元素。

4、contains(Object o);//是否包含

5、contains(Collection col);//是否包含集合。




package it18zhang;


import java.util.ArrayList;

import java.util.List;


/*

 * *1、remove(int index);//删除指定位置的元素

2、remove(Object o);//删除指定对象,考查删除对象的规则是什么?

3、removeAll(Collection col);//删除指定集合中的所有元素。

4、contains(Object o);//是否包含

5、contains(Collection col);//是否包含集合。

 */


public class removeDemo {


public static void main(String[] args) {

// TODO Auto-generated method stub

List<Student> list=new ArrayList<Student>();

Student s1=new Student("s1",10);

Student s2=new Student("s2",11);

Student s3=new Student("s3",11);

Student s4=new Student("s4",12);

System.out.println("通过add添加对象");

list.add(s1);

list.add(s2);

list.add(s3);

list.add(s4);

getlist(list);

System.out.println("通过remove(object o)删除对象");

list.remove(s1);

list.remove(s2);

getlist(list);

System.out.println("通过removeall删除所有对象");

list.removeAll(list);

getlist(list);

System.out.println("通过obtain判断是否包含");

System.out.println("是否包含了s1"+list.contains(s1));

System.out.println("是否包含了s4"+list.contains(s4));

System.out.println("通过obtainall是否包含列表");

System.out.println("是否包含"+list.containsAll(list));

}


private static void getlist(List<Student> list) {

// TODO Auto-generated method stub

for(int i=0;i<list.size();i++){

Student s=list.get(i);

System.out.println("这是第"+i+"学生"+s.getName()+s.getAge());

}

}


}


class Student{

private int age;

private String name;

public Student(String name, int age) {

// TODO Auto-generated constructor stub

this.name=name;

this.age=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;

}

}


大数据第10天

标签:list

原文地址:http://wwywinnie.blog.51cto.com/10421959/1763350

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!