File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary String" Watch "Binary String" New topic
Author

Binary String

Travis Gn
Greenhorn

Joined: Sep 11, 2003
Posts: 19
I have four binary string stored in an array:
[1100001]
[1100011]
[1100010]
[1100011]
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
Bartender

Joined: Aug 20, 2001
Posts: 1817

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
Greenhorn

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
Sheriff

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]
 
 
subject: Binary String