Hi,
i have this string = "1111111111"
if i want to replace 4th character to '0', how can i do that? i think i can not use replace function for this...
anyone can help?
When dealing with Strings in Java, it's good to thing of the "String" class as an unchangable string of characters. To deal with a string of characters that you can change, you should use the StringBuffer class.
This is the Javadoc description of the StringBuffer class:
A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
Anyway, the code for doing what you want to do would look like this if you chose to use the StringBuffer
Thank you so much both of u. since i'm new to java your tips are very helpful. Actually, i did different way(not as professional code ^^), but i will convert them to use buffer. thx again.
oh, thx for toCharArray() function too.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.