Created
January 20, 2017 19:47
-
-
Save salamander2/2742a3deb50ff9cbff3df4274b6c7d62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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