【去除集合中字符串的重复值-2】

package com.yjf.esupplier.common.test;

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

/**
 * @author shusheng
 * @description 去除集合中字符串的重复值(字符串的内容相同)
 * @Email [email protected]
 * @date 2018/12/12 16:55
 */
public class ArrayListDemo1 {

    public static void main(String[] args) {
        ArrayList array = new ArrayList();
        array.add("hello");
        array.add("world");
        array.add("world");
        array.add("world");
        array.add("java");
        array.add("java");
        array.add("hello");
        array.add("hello");
        array.add("software");

        for(int x=0;x<array.size()-1;x++){
            for(int y=x+1;y<array.size();y++){
                if(array.get(x).equals(array.get(y))){
                    array.remove(y);
                    y--;
                }
            }
        }

        Iterator it = array.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

    }

}

猜你喜欢

转载自www.cnblogs.com/zuixinxian/p/10340839.html
今日推荐