Created
May 5, 2016 15:42
-
-
Save tttomat19/05bb30756252fb1fac07247c68caac00 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Created by mfedorov on 05.05.2016. | |
*/ | |
public class SplitterTest { | |
@Test | |
public void splitter() { | |
List<String> splitted = split("aabbccddee", 3); | |
System.out.println(splitted); | |
splitted = split("", 2); | |
System.out.println(splitted); | |
splitted = split("aaaaaaaddddddd", 1); | |
System.out.println(splitted); | |
splitted = split("asdf", 20); | |
System.out.println(splitted); | |
} | |
public static List<String> split(String in, int fixedLength) { | |
assert fixedLength > 0; | |
List<String> splitted = new ArrayList<String>(); | |
for (int i = 0; i < in.length(); i = i + fixedLength) { | |
if (i + fixedLength >= in.length()) { | |
System.out.println(1); | |
splitted.add(in.substring(i, in.length())); | |
} else { | |
System.out.println(2); | |
splitted.add(in.substring(i, i + fixedLength)); | |
} | |
} | |
return splitted; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment