Skip to content

Instantly share code, notes, and snippets.

@tttomat19
Created May 5, 2016 15:42
Show Gist options
  • Save tttomat19/05bb30756252fb1fac07247c68caac00 to your computer and use it in GitHub Desktop.
Save tttomat19/05bb30756252fb1fac07247c68caac00 to your computer and use it in GitHub Desktop.
/**
* 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