you can take the help of Set collection

int end = arr.length;
Set<Integer> set = new HashSet<Integer>();

for(int i = 0; i < end; i++){
  set.add(arr[i]);
}

now if you will iterate through this set, it will contain only unique values. Iterating code is like this :

Iterator it = set.iterator();
while(it.hasNext()) {
  System.out.println(it.next());
}
Answer from Android Killer on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-remove-duplicate-elements-from-the-array
Java Program to Remove Duplicate Elements From the Array - GeeksforGeeks
July 23, 2025 - Given an array, the task is to remove the duplicate elements from an array. The simplest method to remove duplicates from an array is using a Set, which automatically eliminates duplicates. This method can be used even if the array is not sorted.
๐ŸŒ
Codementor
codementor.io โ€บ community โ€บ 5 effective methods in java to remove array duplicates while preserving original order
5 Effective Methods in Java to Remove Array Duplicates while Preserving Original Order | Codementor
January 26, 2024 - Time complexity: O(nยฒ) - nested loop to compare each element with others ยท Space complexity: O(1) - no auxiliary space is needed. To sum up, we have explored five different methods for removing duplicates from an unsorted array in Java: ArrayList, Set, Map, Stream API, and in-place removal without auxiliary data structures.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ solving-the-remove-duplicates-from-sorted-array-problem-on-leetcode-a-java-walkthrough-2ea4e383545c
Java Solution: Remove Duplicates from Array | Medium
February 1, 2024 - In this walkthrough, we will address the problem of removing duplicates from a sorted array using Java, as presented in the 26th problem on LeetCode. We will explore three distinct solutions to ensure a comprehensive understanding. You will find each solution explained with commented code and a detailed step-by-step explanation to ensure a comprehensive understanding after the conclusion. Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once, keeping the relative order of the elements the same.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ removing-duplicate-elements-in-java-array
Removing Duplicate Elements In Java Array | Edureka
November 29, 2022 - The unsorted array is first sorted using the Array.sort() method. import java.util.Arrays; public class Main{ public static int removeDuplicates(int array[], int n){ if(n==0 || n==1){ return n; } int[] temp = new int[n]; int j = 0; for (int ...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ remove-duplicate-elements-from-arraylist
Java Program to Remove duplicate elements from ArrayList | Vultr Docs
December 6, 2024 - This code effectively removes duplicates by leveraging the unique nature of HashSet. The ArrayList is converted to a HashSet which automatically drops all duplicate items since a set only allows unique elements. Subsequently, the unique values are transferred back to an ArrayList. Utilize Javaโ€™s Stream API for a modern approach.
๐ŸŒ
PREP INSTA
prepinsta.com โ€บ home โ€บ dsa with java โ€บ java program for removing duplicates elements from an array
Removing Duplicates elements from an array in Java | PrepInsta
October 11, 2022 - import java.util.*; public class Main{ public static void main(String[] args){ Scanner scn=new Scanner(System.in); int n=scn.nextInt(); int[] arr=new int[n]; ... public static void duplicateElement(int arr[], int n) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] == arr[j] && arr[i] != 0) { arr[j] = 0; } } if(arr[i]!=0){ System.out.print(arr[i]+" "); } } System.out.println(); }
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ examples โ€บ remove-duplicate-elements-from-arraylist
Java Program to Remove duplicate elements from ArrayList
import java.util.ArrayList; import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; class Main { public static void main(String[] args) { // create an arraylist from the array // using asList() method of the Arrays class ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 1, 3)); System.out.println("ArrayList with duplicate elements: " + numbers); // create a stream from arraylist Stream<Integer> stream = numbers.stream(); // call the distinct() of Stream // to remove duplicate elements stream = stream.distinct(); // convert the stream to arraylist numbers = (ArrayList<Integer>)stream.collect(Collectors.toList()); System.out.println("ArrayList without duplicate elements: " + numbers); } }
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ array โ€บ java-array-exercise-16.php
Java - Remove duplicate elements from an array
int no_unique_elements = my_array.length; // Comparing each element with all other elements to find duplicates. for (int i = 0; i < no_unique_elements; i++) { for (int j = i + 1; j < no_unique_elements; j++) { // If any two elements are found equal (a duplicate is found)....
๐ŸŒ
NxtWave
ccbp.in โ€บ blog โ€บ articles โ€บ remove-duplicates-from-array-java
Remove Duplicates from Array Java: A Complete Guide
This approach involves iterating through the array and adding each element to the ArrayList only if it doesn't already exist. Create an ArrayList to store unique elements. Iterate through the array.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-program-to-remove-duplicate-element-in-an-array
Java Program to Remove Duplicate Element in an array - javatpoint
Java Program to Remove Duplicate Element in an Array with examples of fibonacci series, armstrong number, prime number, palindrome number, factorial number, bubble sort, selection sort, insertion sort, swapping numbers etc.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java array โ€บ java โ€“ find, count and remove duplicate elements from array
Java - Find, Count and Remove Duplicate Elements from Array
November 9, 2022 - If we remove all the duplicate elements from the Set, it will contain only the unique elements. distinctElementsSet.removeAll(Arrays.asList(duplicateElementsArray)); Integer[] uniqueElementsArray = distinctElementsSet.toArray(Integer[]::new); System.out.println("Unique elements in the array : " + Arrays.toString(uniqueElementsArray)); //[2, 4] In this short Java tutorial, we learned two different ways to find and count duplicate elements in a Java array.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ blogs โ€บ remove-duplicates-from-array-in-java
Remove Duplicates From Array In Java
December 20, 2021 - Array Before Removing Duplicates: 1 3 4 5 1 3 4 5 4 2 6 5 7 Array After Removing Duplicates: 1 3 4 5 2 6 7 ยท Sets in Java store unique elements only. We can easily remove duplicates from an array by storing the array elements in a linked hashset. ...
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ remove-duplicates-from-sorted-array
Remove Duplicates from Sorted Array - LeetCode
Can you solve this real interview question? Remove Duplicates from Sorted Array - Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place [https://en.wikipedia.org/wiki/In-place_algorithm] such that each unique element appears only once.
๐ŸŒ
PrepBytes
prepbytes.com โ€บ home โ€บ java โ€บ java program for removing duplicates elements from an array
Java Program for Removing Duplicates Elements from an Array
May 18, 2023 - Ans. Some of the methods that can be used to remove duplicate elements from an array in Java include using a HashSet, using a TreeSet, and using a for loop with an if statement.
๐ŸŒ
Systech
systechgroup.in โ€บ home โ€บ java program to remove duplicate elements in an array
Java Program to Remove Duplicate Elements in an Array
October 11, 2025 - Implement a Java program to remove duplicate elements from an array using HashSet, ensuring unique values with clear code examples and step-by-step instructions.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ remove-duplicate-element-in-a-Java-array
Remove duplicate element in a Java array
This package provides a class named ArrayUtils using the remove() method of this class you can delete the detected duplicate elements of the given array. import java.util.Arrays; import java.util.Scanner; import org.apache.commons.lang3.ArrayUtils; public class DeleteDuplicate { public static ...
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ array โ€บ java-array-exercise-33.php
Java - Remove duplicate elements from a given array
System.out.println("\nThe new length of the array is: " + array_sort(nums)); } // Define a method named array_sort that takes an array of integers as input. public static int array_sort(int[] nums) { // Initialize an index variable to 1. int index = 1; // Iterate through the array, starting from the second element. for (int i = 1; i < nums.length; i++) { // Check if the current element is different from the previous element. if (nums[i] != nums[index - 1]) // If different, update the element at the current index. nums[index++] = nums[i]; } // Return the new length of the array. return index; } } ... Write a Java program to remove duplicates from a sorted array in-place.
๐ŸŒ
Just Academy
justacademy.co โ€บ blog-detail โ€บ how-to-remove-duplicate-elements-from-array-in-java
How to Remove Duplicate Elements from Array in Java
5) Iterate and remove duplicates in place: Iterate through the array and remove duplicates in place by shifting elements to fill the removed duplicates. This method may require more complex logic and potentially affect the original order of elements. 6) Use Java 8 Streams: You can use Java 8 Streams to easily remove duplicates from an array.