This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm curious as to why you need to do this. Maybe there's a
better way to address the problem. What you want is quite
straight forward using String's length() and toCharArray()
methods. What have you tried so far?
String c = String a + String b;
byte ab = convert String c to byte array;
Now I want to separate byte ab to recover the String a and String b;
How do I do this?
A related question: how do you turn String c back into Strings a and b? What separates the two? If you know this, you can turn byte ab back into String c first, then split that one.
I will tell you this: unless you use a special separator sequence (e.g. |) you won't be able to. If a == "Hello" and b == "World", c will become "HelloWorld". If I need to split that into a and b again, I have "HelloWorld".length() different options:
- "" and "HelloWorld"
- "H" and "elloWorld"
- "HelloWorl" and "d"
- "HelloWorld" and ""