Skip to content

Automation Testing

Java, Selenium etc..

  • Java
  • Selenium
  • Interview Question
  • Core Java Coding
  • Rest APIS
  • Manual Testing
  • SQL Queries
  • Postman
  • Toggle search form

Remove Duplicates From Int Array

Posted on May 8, 2023May 8, 2023 By admin

There are many ways to remove duplicate items

A) Using for Loop

package InterViewQuestions;
public class RemoveDuplicatesFromArray {
    public static void main(String[] args) {
        Integer[] integer_Array = {50, 50, 100, 100, 99, 99, 9, 9, 100, 100};
        int [] temp = new int[integer_Array.length];
        for(int i =0; i< integer_Array.length; i++){
            for(int j = i+1; j < integer_Array.length-1; j ++ ){
                if(integer_Array[i] == integer_Array[j]){
                    integer_Array[i] =0;
                }else{
                    temp[i] = integer_Array[i];
                }
            }
        }
        for(int i =0; i<temp.length; i++){
            if(temp[i] !=0){
                System.out.println(temp[i]);
            }

        }
    }
}

B) Using set collection 
public static void removeDupInIntArray(int[] ints){
        Set<Integer> setString = new LinkedHashSet<Integer>();
        for(int i=0;i<ints.length;i++){
            setString.add(ints[i]);
        }
        System.out.println(setString);
    }
Core Java Coding Questions, Java Basic Interview Questions(company wise) Tags:Remove Duplicates From Int Array

Post navigation

Previous Post: Java Basic Interview Questions
Next Post: GUI Testing for Payment Gateway

Recent Posts

  • Can you write java program for prime number 1to 50 and skip printing 30 and 40 numbers
  • Java 8 features
  • Imp Links
  • Create a Java program to store the Name and Salary of employees
  • String Char Counts Using Collections

Recent Comments

No comments to show.

Copyright © 2022 okhalaTech