aspose file tools*
The moose likes Beginning Java and the fly likes Binary String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary String" Watch "Binary String" New topic

Binary String

Travis Gn

Joined: Sep 11, 2003
Posts: 19
I have four binary string stored in an array:
I want to randomly change one bit of the String in each array. From 0 to 1 or 1 to 0. Is there an easy way to change one bit in a string? Thank you for any help.

I need more help!
Joel McNary

Joined: Aug 20, 2001
Posts: 1815
Assuming that I am reading your question correctly, you are stating that you have an array containg four strings:

To answer your question: You can't. Strings are immutable objects; that means, once assigned a value, they cannot change.
Do not fear, however! Java is not a language that would leave you hanging like that. Use the StringBuffer class -- it is mutable.

(If you can follow how that bit of code works, then you're doing well....)

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Travis Gn

Joined: Sep 11, 2003
Posts: 19
Thanks for the help that worked perfectly. Do you know if you can create an array of stringbuffers?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Do you know if you can create an array of stringbuffers?
Much like creating an array of Strings, or of anything else.
StringBuffer array = new StringBuffer[someSize];
You might want to read up on arrays in Java in the Arrays lesson of Sun's Java Tutorial. Another good introductory tutorial to reference is Bradley Kjell's Introduction to Computer Science using Java. Arrays start in chapter 46.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Binary String
Similar Threads
Reality Check!
what is Binary number
Binary to Decimal conversion
Array initialization
How to convert binary to decimal?