Q: How can I get the second line of a string in a clean way? If I have String c = a + "\n" + b; given c what is the best way to get b?
Using c.substring(c.indexOf("\n") + 1, c.length); seems error prone and does not take into account any whitespace after \n.
I want only b

A: you can use split method like this: c.split("\n")[1]

A: c.substring(c.indexOf("\n") + 1).trim(); 


A: Use c.split("\n")[1] to get the second part of the string. [0]th element of the array will be a, in case you need it as well.

A: Considering you don't need white spaces.
String a = "xyz ";
String b = "    bcd";
String c = a + "\n" + b;
System.out.println(c.substring(c.indexOf("\n") + 1).replaceFirst("\\s++", ""));

Output: 
bcd


A: You may use replaceAll assuming a and b variables won't contain any newline characters.
System.out.println(str.replaceAll(".*\\n", ""));


A: try 
String formula_regex= "\\n";
line = c.split(formula_regex);

System.out.println(line)

