How to split the string "Thequickbrownfoxjumps"
to substrings of equal size in Java.
Eg. "Thequickbrownfoxjumps"
of 4 equal size should give the output.
["Theq","uick","brow","nfox","jump","s"]
Similar Question:
How to split the string "Thequickbrownfoxjumps"
to substrings of equal size in Java.
Eg. "Thequickbrownfoxjumps"
of 4 equal size should give the output.
["Theq","uick","brow","nfox","jump","s"]
Similar Question:
Well, it's fairly easy to do this by brute force:
I don't think it's really worth using a regex for this.
EDIT: My reasoning for not using a regex:
You can use
substring
fromString.class
(handling exceptions) or from Apache lang commons (it handles exceptions for you)Put it inside a loop and you are good to go.
i use the following java 8 solution: