Monday, 2 May 2022

Remove duplicate in the String

 Remove duplicate in the String 


        public void removeDuplicateInString() {

String input="Helle";

String output="";

for(char ch:input.toCharArray()) {

if(!output.contains(String.valueOf(ch))) {

output+=ch;

}

}

System.out.println(output);

}


o/p: Hele

No comments:

Post a Comment

Switch case in Java

 Problem statement: Return the capital of a state based on input state          public String getCapital(String state){               switch...