怎样取消网站备案,什么网站专门做外围的,杭州公司网站制作维护,做公司网站要注意什么/* * 需求#xff1a;ArrayList去除集合中字符串的重复值 * * 分析#xff1a; * 1.创建一个集合对象 * 2.添加多个字符串元素 * 3.创建一个新的集合 * 4.拿旧集合中的元素到新集合中去找 * A#xff1a;有则 不要 * B:没有则添加到新集合中 * 5.遍历输出 新集合 */ packa… /* * 需求ArrayList去除集合中字符串的重复值 * * 分析 * 1.创建一个集合对象 * 2.添加多个字符串元素 * 3.创建一个新的集合 * 4.拿旧集合中的元素到新集合中去找 * A有则 不要 * B:没有则添加到新集合中 * 5.遍历输出 新集合 */ package com.ma.arraylist;import java.util.ArrayList;
import java.util.Iterator;/*** ArrayList去除集合中字符串的重复值* author ma**/
public class ArrayListDemo {/** 需求ArrayList去除集合中字符串的重复值 * * 分析* 1.创建一个集合对象* 2.添加多个字符串元素* 3.创建一个新的集合* 4.拿旧集合中的元素到新集合中去找* A有则 不要* B:没有则添加到新集合中* 5.遍历输出 新集合*/public static void main(String[] args) {//1.创建一个ArrayList集合对象ArrayList arrList new ArrayList();//向ArrayList添加字符串元素arrList.add(hello);arrList.add(world);arrList.add(hello);arrList.add(java);arrList.add(你好);arrList.add(世界);arrList.add(你好);arrList.add(爪哇);//3.创建一个新的集合ArrayList arrList1 new ArrayList();/**4.拿旧集合中的元素到新集合中去找* A有则 不要* B:没有则添加到新集合中*///得到迭代器Iterator it arrList.iterator();//遍历集合arrListwhile (it.hasNext()) {String str (String) it.next();//如arrlist1中不包含str则把str添加支arrList1中if(!arrList1.contains(str)){arrList1.add(str);}}//5.遍历输出 新集合//得到迭代器Iterator it1 arrList1.iterator();//遍历输出 新集合while (it1.hasNext()) {String str1 (String) it1.next();System.out.println(str1);}}
}输出结果 hello world java 你好 世界 爪哇转载于:https://www.cnblogs.com/majingang/p/9018734.html