实例: package com . xhy . xczx . test ; import java . util . * ; /** * 〈测试类〉 * * @author Barrett * @version 1.0.0 * @time 2020/1/21 */ public class JavaTest1 { public static void main ( String [] args ) { /** List集合的去重
实例:
package com.xhy.xczx.test;import java.util.*;
/**
* 〈测试类〉
*
* @author Barrett
* @version 1.0.0
* @time 2020/1/21
*/
public class JavaTest1 {
public static void main(String[] args) {
/** List集合的去重 **/
List<String> list = new ArrayList<String>();
list.add("s1");
list.add("s3");
list.add("s5");
list.add("s4");
list.add("s4");
list.add("s2");
list.forEach(e -> System.out.print(e + " "));
System.out.println();
Set<String> linkedHashSet = new LinkedHashSet<>(list);
List<String> list1 = new ArrayList<>();
linkedHashSet.forEach(e -> list1.add(e));
list1.forEach(e -> System.out.print(e + " "));
}
}
结果: