Skip to content

Instantly share code, notes, and snippets.

@salamander2
Created January 20, 2017 19:47
Show Gist options
  • Save salamander2/2742a3deb50ff9cbff3df4274b6c7d62 to your computer and use it in GitHub Desktop.
Save salamander2/2742a3deb50ff9cbff3df4274b6c7d62 to your computer and use it in GitHub Desktop.
public class SplittingUp {
public static void main(String args[]) {
String str = "this is a long string. With lots of words. And other stuff. It just goes on and on and on";
String[] strArray = str.split(" ");
int slen = 20;
String newStr = "";
for (int i=0; i< strArray.length; i++) {
newStr += strArray[i] + " ";
if (newStr.length() > slen) {
newStr = newStr.trim();
newStr += "\n";
slen +=20;
}
}
System.out.println(str);
System.out.println("12345678901234567890");
System.out.println(newStr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment