Arraylist的基本操作:
    1、排序:两种方法:
    (1)自然排序
    1.Student类中实现 Comparable接口
    2.重写Comparable接口中的Compareto方法(都是发生在JavaBean中)
    (2)比较器排序
    在主类中重写Comparator接口中的Compare方法
    (在JavaBean中不必在继承Comparable)
    如Collections.sort(lists, new Comparator() {
    @Override
    public int compare(Bean o1, Bean o2) {

    1. **int **num0=o1.**name**.length()-o2.**name **.length();<br /> **int **num1=num0==0?(o1.**age**-o2.**age**):num0;<br /> **return **num1;<br /> }<br />});``

    测试类:
    `package com.chl.Collection;

    import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

    import java.util.ArrayList;
    import java.util.Collections;

    public class List {
    public static void main(String[] args) {
    ArrayList lists = new ArrayList();
    Bean stu=new Bean();
    stu.setName(“张”);
    stu.setAge(8);

    1. Bean stu1=**new **Bean();<br /> stu1.setName(**"李四"**);<br /> stu1.setAge(7);
    2. Bean stu2=**new **Bean();<br /> stu2.setName(**"王三五"**);<br /> stu2.setAge(0);
    3. Bean stu3=**new **Bean();<br /> stu3.setName(**"张"**);<br /> stu3.setAge(8);
    4. lists.add(stu);<br /> lists.add(stu1);<br /> lists.add(stu2);<br /> lists.add(stu3);
    5. Collections._sort_(lists);
    6. **for **(Bean list : lists)<br /> {<br /> _//按年龄排序_ _System.**_out_**.print(list.getName()+**"----"**+list.getAge());<br /> System.**_out_**.print(**" "**);<br /> }<br /> }<br />}

    <br />JavaBean:<br />package com.chl.Collection;

    public class Bean implements Comparable{
    public String getName() {
    return name;
    }

    1. **public void **setName(String name) {<br /> **this**.**name **= name;<br /> }
    2. **public int **getAge() {<br /> **return age**;<br /> }
    3. **public void **setAge(**int **age) {<br /> **this**.**age **= age;<br /> }
    4. **public **String **name**;<br /> **public int age**;
    5. @Override<br /> **public int **compareTo(Bean o) {<br /> _//0 1 是正序 -1是降序<br /> //return this.age-o.age;
    6. //按姓名长度和年龄排序<br /> _**int **num0=**this**.**name**.length()-o.**name **.length();<br /> **int **num1=num0==0?(**this**.**age**-o.**age**):num0;<br /> **return **num1;<br /> }<br />}`

    2、Arraylist去重:
    `package com.chl.Arlist;

    import java.util.ArrayList;
    import java.util.Iterator;

    public class test {
    public static void main(String[] args) {
    _//原集合
    _ArrayList lists = new ArrayList();
    lists.add(10);
    lists.add(20);
    lists.add(10);
    lists.add(40);
    lists.add(80);
    lists.add(5);
    lists.add(80);

    1. _//去重后集合<br /> _ArrayList list1 = **new **ArrayList();
    2. **for**(**int **i=0;i<lists.size();i++)<br /> {<br /> _//去重<br /> _**if**(list1.contains(lists.get(i)))<br /> {<br /> **continue**;<br /> }<br /> **else<br /> **{<br /> list1.add(lists.get(i));<br /> }<br /> }<br /> Iterator its=list1.iterator();
    3. **while**(its.hasNext())<br /> {<br /> System.**_out_**.println(its.next());<br /> }
    4. }<br />}`<br />**2、Arraylist线程安全:可以使用线程锁保证其线程安全。**