Write a Java program to print all unique element in an array


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Arrays;
  2. import java.util.Set;
  3. import java.util.TreeSet;
  4. public class Javaexcercise
  5. {
  6.  
  7. public static void main(String[] args)
  8. {
  9. Integer[] numbers = {1, 1, 2, 1, 3, 4, 5};
  10. Set<Integer> uniqKeys = new TreeSet<Integer>();
  11. uniqKeys.addAll(Arrays.asList(numbers));
  12. System.out.println("uniqKeys: " + uniqKeys);
  13. }
  14. }

Result

java techstudy.org

     





Related Topics




Popular Posts