Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java replace second char of a string

class Main
{
    public static void main(String[] args)
    {
        String str = "Techie Delight";
        char ch = '_';
        int pos = 6;
 
        StringBuilder sb = new StringBuilder(str);
 
        // replace character at the specified position
        sb.setCharAt(pos, ch);
        str = sb.toString();
 
        // print the modified string
        System.out.println(str);
    }
}
Source by www.techiedelight.com #
 
PREVIOUS NEXT
Tagged: #java #replace #char #string
ADD COMMENT
Topic
Name
1+5 =