Answers for "how to change the position of character in string in java"

0

how to change the character of a string in java

// You cannot change the characters of a string in java
// But you can make it work
// For Example: A Program to change 'r' to 'a'
class Main{
  public static void main(String args[]){
    String str = "return";
    String res = "";
    for(int i = 0; i<str.length(); i++){
      if(str.charAt(i)=='r'){
        res+='a';
      }
      else{
        res+=str.charAt(i);
      }
    }
    System.out.print("Result = "+res);
  }
}
Posted by: Guest on February-20-2022

Code answers related to "how to change the position of character in string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language