首页 > 其他 > 详细

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

时间:2019-01-31 11:25:57      阅读:133      评论:0      收藏:0      [点我收藏+]
package com.yjf.esupplier.common.test;

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

/**
 * @author shusheng
 * @description 去除集合中字符串的重复值(字符串的内容相同)
 * @Email shusheng@yiji.com
 * @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());
        }

    }

}

 

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

原文:https://www.cnblogs.com/zuixinxian/p/10340839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!