合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 打印给定整数数组的所有不同元素 > 原文: [https://www.geeksforgeeks.org/print-distinct-elements-given-integer-array/](https://www.geeksforgeeks.org/print-distinct-elements-given-integer-array/) 方法: 1.将所有输入整数放入哈希图的键 2.在循环外部打印 keySet ## Java ```java import java.util.HashMap; public class UniqueInArray2 {     public static void main(String args[])     {         int ar[] = { 10, 5, 3, 4, 3, 5, 6 };         HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();         for (int i = 0; i < ar.length; i++) {             hm.put(ar[i], i);         }         // Using hm.keySet() to print output reduces time complexity. - Lokesh         System.out.println(hm.keySet());     } } ```