For example I have a string "1234" that I want to break into two strings "12", "34". Is there any method for doing that? How?
You might use the substring function:
"1234".substring(0, 2);
"1234".substring(2, 4);
It takes a begin index and an end index, returning the substring between the two.
If you want to generically solve this problem (let's say you want to split a string in half), then extend what luvieere suggested...
String aString = "1234";
int length = aString.length();
System.out.println(aString.substring(0,length / 2));
System.out.println(aString.substring(length / 2,aString.size());
Something like that. (Of course, that doesn't handle an odd-length string, but I'll leave that up to you.)
Whenever you have to do something with Strings, then have a look at the static methods declared on the String class.
In fact String.substring() can't 'break' a String in two parts, but it returns a part of the original String and you can assemble your break requirement with two substring operations, like luvieere explained in another answer.
Usually you use String.split() to break a String in parts, but with substring there's an easier solution for your problem.
use the string split method
for example
String s = "1234";
s.Split(".{2}.{2}" = {"12", 23"} // a String array
You could also you String Tokenizer. If there is a character that you want to split the string with.
For example "Stack Overflow", could be split into two tokens "Stack" and "Overflow" using the white-space (" ").
If your question is actually "what separator should I use to demarcate individual values in a string", the answer is it doesn't matter as long as it's not going to be present in your normal input data. For example, you could use "^|*" as your separator in most situations because it's unlikely to be coincidentally present in normal input data.
If your question is "how do I split a string delimited by a known separator", you can use StringTokenizer, String.split() with a regex, or String.indexOf() combined with String.substring().