String are immutable in Java. You can’t change them.
You need to create a new string with the character replaced.
String myName = "domanokz"; String newName = myName.substring(0,4)+'x'+myName.substring(5);
Or you can use a StringBuilder:
StringBuilder myName = new StringBuilder("domanokz"); myName.setCharAt(4, 'x'); System.out.println(myName);
Related Posts:
- Converting String to “Character” array in Java
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- How can I check if a single character appears in a string?
- Difference between String replace() and replaceAll()
- How to compare character ignoring case in primitive types
- Removing double quotes from a string in Java
- How do I convert a String to an int in Java?
- How to format strings in Java
- Java – Convert integer to string [duplicate]
- How to split a string in Java
- How do I compare strings in Java?
- How to convert a char to a String?
- How to convert/parse from String to char in java?
- Reverse a string in Java
- Reverse a string in Java
- Java String Split by “|”
- Convert String to double in Java
- Java String new line
- How to check if a String contains another String in a case insensitive manner in Java?
- Java split string to array [duplicate]
- String concatenation: concat() vs “+” operator
- How to remove the last character from a string?
- Java string to date conversion
- How to replace � in a string
- What are all the escape characters?
- Best way to convert an ArrayList to a string
- How to split a String by space
- String interpolation in Java 14 or 15
- How to remove single character from a String
- How to parse this string in Java?
- How to convert any Object to String?
- How to split a string in Java
- Illegal Escape Character “\”
- Can I multiply strings in Java to repeat sequences?
- What does regular expression \\s*,\\s* do?
- How to convert a Binary String to a base 10 integer in Java
- Left Hand Side of an Assignment must be a Variable CharAt
- How to capitalize the first letter of a String in Java?
- catDog string problem at Codingbat.com
- Java way to check if a string is palindrome
- Return string Input with parse.string
- What is the difference between String.subString() and String.subSequence()
- Java compressing Strings
- How can I remove a character from a string using JavaScript?
- Explain the use of a bit vector for determining if all characters are unique
- Convert array of strings into a string in Java
- How to remove single character from a String
- How to remove single character from a String
- What is Java String interning?
- What is Java String interning?
- What is Java String interning?
- Why is there no String.Empty in Java?
- Java split string to array
- Using Enum values as String literals
- int cannot be converted to string?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- Convert String to int array in java
- Converting String Array to an Integer Array
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- java.lang.NumberFormatException: empty String
- How to check if a String is numeric in Java
- How to replace a substring of a string
- Converting A String To Hexadecimal In Java
- Immutable class?
- Converting a string to an integer on Android
- Simple way to repeat a string
- Java end of file
- Unclosed Character Literal error
- Java: how to initialize String[]?
- Regular Expressions on Punctuation
- How to extract a substring using regex
- difference between equals() and hashCode()
- Java String to SHA1
- Determine if a String is an Integer in Java [duplicate]
- How to convert a String to CharSequence?
- How do I convert a String to a BigInteger?
- How can I remove a substring from a given String?
- Java get String CompareTo as a comparator object
- How to use regex in String.contains() method in Java
- How to swap String characters in Java?
- Get an OutputStream into a String
- Difference between string object and string literal
- How to convert a String into an ArrayList?
- java: use StringBuilder to insert at the beginning
- How do I get the last character of a string?
- Cannot invoke toString() on the primitive type int
- Append a single character to a string or char array in java?
- convert string to arraylist
in java - How do I replace a character in a string in Java?
- How to insert multiple tabs string in java?
- Append a single character to a string or char array in java?
- String is immutable. What exactly is the meaning?
- Why cannot cast Integer to String in java?
- Occurrences of substring in a string
- Quotation marks inside a string
- In Java, how do I parse XML as a String instead of a file?
- Fastest way to put contents of Set
to a single String with words separated by a whitespace? - How to know if a given string is substring from another string in Java