Replace a character at a specific index in a string?

后端 未结 8 1025
我在风中等你
我在风中等你 2020-11-22 03:22

I\'m trying to replace a character at a specific index in a string.

What I\'m doing is:

String myName = \"domanokz\";
myName.charAt(4) = \'x\';
         


        
8条回答
  •  悲&欢浪女
    2020-11-22 04:01

    this will work

       String myName="domanokz";
       String p=myName.replace(myName.charAt(4),'x');
       System.out.println(p);
    

    Output : domaxokz

提交回复
热议问题