Tuesday 17 July 2018

Find duplicate elements and count in java- Interview question Java/Selenium

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class DuplicateElementsInArray {


public static void main(String[] args) {
String str = "Java isap latformi111111end 000 666 entla bsbcascvgsvchgnguage";
Map<Character,Integer> duplicate = new HashMap<Character,Integer>();
char[] carray = str.toCharArray();
for (Character c:carray) {
if (c != ' ') {
if(duplicate.containsKey(c))
{
duplicate.put(c, duplicate.get(c)+1);
}
else {
duplicate.put(c, 1);
     }
}
}
Set<Character> set = duplicate.keySet();

for (Character c:set) {
if(duplicate.get(c)>1)
{
System.out.println(c+" "+duplicate.get(c));
}
}
// TODO Auto-generated method stub

}

}

*************************************************

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...