程序代码:
import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.stream.Collectors; public class Test0515 { public static void main(String[] args) { // 输出不重复的整数 Scanner scanner = new Scanner(System.in); System.out.print("Please input the number:"); int number = scanner.nextInt(); System.out.print("Please input some integers:"); List<Integer> numArr = new ArrayList<>(); for(int i = 0;i < number;i++) numArr.add(scanner.nextInt()); scanner.close(); Map<Integer, Integer> map = numArr.stream(). collect(Collectors.toMap(e->e, e->1, (e, e2)->e+e2)); System.out.println(map); map.forEach((k,v)->{ if(v==1) System.out.println(k); }); } }
Please input the number:
5
Please input some integers:1
2
2
3
4
{1=1, 2=2, 3=1, 4=1}
1
3
4
剑栈风樯各苦辛,别时冰雪到时春