How to find duplicate characters in a string using java

How to find duplicate characters in a string using java

Java Basics

4 года назад

57,425 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@user-bk8kz5fg8r
@user-bk8kz5fg8r - 14.10.2023 11:56

String a="abcdef";
String b="dghijk";
String c= "lmnopa"; can any one help me from these 3 strings to be compared and find duplicates in java8

Ответить
@diomondkkk3104
@diomondkkk3104 - 07.07.2023 20:05

Clean nhi dikh raha h

Ответить
@upendaarnunavath5469
@upendaarnunavath5469 - 26.04.2023 18:37

Thank you sir.

Ответить
@YouTubeShorts-.
@YouTubeShorts-. - 28.09.2022 09:32

Need to explain How it works that's the important

Ответить
@vibe2943
@vibe2943 - 12.07.2022 23:33

Fucking no one tell what happen when that duplicate value come more than twice . Ignorance

Ответить
@sriinfo8590
@sriinfo8590 - 15.06.2022 07:55

Good but You have explain more you just going on by writing the code who wil understand

Ответить
@MustafizurRahamanMustak
@MustafizurRahamanMustak - 25.04.2022 17:00

More Optimised Code:

public class Repeated {
public static void main(String[] args) {
String name = "Rahaman";
int count;
char ch [] = name.toCharArray();
for (int i = 0; i <name.length() ; i++) {
count =1;
for (int j = i+1; j < name.length(); j++) {
if (ch[i] == ch[j] && ch[i] != ' ') {
count++;
ch[j] = '0';
}
}

if(count> 0 && ch[i] !='0'){
System.out.print(" " + ch[i] );
}

}

}
}

Ответить
@manidhar334u
@manidhar334u - 14.04.2022 16:00

Time complexity is o(n^2),which is bad, instead you can use hashmap with key as char and value as counter

Ответить
@surya-ow4wr
@surya-ow4wr - 29.03.2022 10:59

It's not working

Ответить
@rohitmiryala8543
@rohitmiryala8543 - 05.12.2021 09:33

how to find frequency of this duplicate characters??

Ответить
@ashu40h
@ashu40h - 26.09.2021 20:00

Very nice bro keep it up very sort and simple

Ответить
@anuraghivare5875
@anuraghivare5875 - 27.07.2021 07:10

Thanks its useful ....❤but Try to give Explaination also because it will be more helpful for beginners who they are doing coding.....

Ответить
@arnabchatterjee1703
@arnabchatterjee1703 - 25.07.2021 18:30

wrong code

Ответить
@vishnusjanardhanan7863
@vishnusjanardhanan7863 - 25.07.2021 15:54

Hey in this..if there are multiple characters like greater than 2 ,it will not work

Ответить
@aravindraj8294
@aravindraj8294 - 18.07.2021 10:40

You simply writing program, you should trace code and explain it.

Ответить
@abdulfareed2585
@abdulfareed2585 - 16.06.2021 18:42

This is wrong
sir

Ответить
@yforyou1342
@yforyou1342 - 15.06.2021 14:05

short and simple solution, keep go on....

Ответить
@dilkiwrites9667
@dilkiwrites9667 - 09.06.2021 09:33

Chutiye agr array me hi convert krna hota to hum string ka kyo search krte

Ответить
@raana2429
@raana2429 - 28.05.2021 09:15

Chala baga explain chesaru sir 🙏

Ответить
@nishantdeep3973
@nishantdeep3973 - 26.05.2021 12:47

Hello sir.. It will not work when one character occurs more than two times i.e sillypointspider, o/p will come as i print two times instead of 1 coz it occured 3 times in a string and will satisfy the condition of second loop also.

Ответить
@purnimacb7638
@purnimacb7638 - 26.05.2021 10:36

This program doesn't work well with string "Hello Beautiful" ??

Ответить
@smilequeensujata6347
@smilequeensujata6347 - 15.04.2021 10:24

if i am giving input string "saraswati" the Above code is not working ,o/p should be s a but o/p coming s a a

Ответить
@srutilata6085
@srutilata6085 - 08.03.2021 17:56

Suppose take input string as "i am going to gym".
Above code is not working.
Actual O/P: i m g o g
Expect o/p should be : i m g o

Thanks,
Sruti

Ответить
@siddharthbattoo7768
@siddharthbattoo7768 - 09.02.2021 10:45

THanks Buddy :)

Ответить
@siddharthatarafder9408
@siddharthatarafder9408 - 31.10.2020 14:38

Excellent !!!

Ответить