#16 : How to find duplicates in array in java using HASHMAP | java programs for selenium interview

preview_player
Показать описание
Please share, support and subscribe.
Follows us on:

#java programs for selenium interview

Automation Framework Questions

Selenium Interview Questions

About Online Rostrum:

This is a tech channel and we are sharing knowledge and helping our community.
Рекомендации по теме
Комментарии
Автор

Great video helped me to understand.Thanks!

milanpronic
Автор

line no 110
you can just do for(int x:map.keySet()){
System.out.println(x);}

Why you do that?

sudarshankumar
Автор

Why is the complexity O(n). Shouldnt it be O(n^2) since you used two loops, One to construct hashmap and the next one to iterate through it to check values

rachnachawla
Автор

public static void main(String[] args) {

int arr[]={123, 456, 567, 123, 567};

Map<Integer, Integer> map = new HashMap<>();

for(int i=0; i<arr.length; i++){
if(map.containsKey(arr[i])){
map.put(arr[i], map.get(arr[i])+1);
}
else{
map.put(arr[i], 1);
}
}

for(Map.Entry<Integer, Integer> entry : map.entrySet()){
if(entry.getValue()>1){
System.out.println("Repecting element is ->" +entry.getKey());
}
}

}

}

niteshpandey
Автор

didnt understand. Unclear explanation.

ankitborbora