Split string to equal length substrings in Java

后端 未结 21 2171
日久生厌
日久生厌 2020-11-22 02:56

How to split the string \"Thequickbrownfoxjumps\" to substrings of equal size in Java. Eg. \"Thequickbrownfoxjumps\" of 4 equal size should give th

21条回答
  •  独厮守ぢ
    2020-11-22 03:31

    You can use substring from String.class (handling exceptions) or from Apache lang commons (it handles exceptions for you)

    static String   substring(String str, int start, int end) 
    

    Put it inside a loop and you are good to go.

提交回复
热议问题