企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 打印给定整数数组的所有不同元素 > 原文: [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());     } } ```