Remove a Character from String in Java

 Remove  a Character from String in Java


In this blog, we will learn how to remove a character from a string in java.We will take input as string and a character (that we want to remove from our string) in java

Code Link

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String s1 = s.next(); //take input String 
char remove = s.next().charAt(0); // take the character that you want to remove
String solu=""; // after removing the desired char it will store the string here
for(int i=0;i<s1.length();i++) {
if(s1.charAt(i)!=remove) {  //if char at ith position is not equal to remove char then it will store the char at our string in sol
solu= solu+s1.charAt(i);
}
}
System.out.println(solu);
}


Other Java Blog Links




Post a Comment

0 Comments