欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java 两list求交集

程序员文章站 2022-03-07 15:20:45
...
String s1 = "50000,100000,200000,300000,500000,";
		String s2 = "10000,30000,50000,100000,";
		String[] a1 = s1.split(",");
		String[] a2 = s2.split(",");
		List<String> list = new ArrayList(Arrays.asList(a1));
		list.retainAll(Arrays.asList(a2)); // list 中的就是交集了
		for(String s : list){
			System.out.println(s);
		}

 

相关标签: Java