I have a hypothetical string with 2500 characters. (myString.length=2500) and I want to split it to several strings per 500 chars and assign this new strings to an Array string.
            Asked
            
        
        
            Active
            
        
            Viewed 121 times
        
    0
            
            
         
    
    
        Hunsu
        
- 3,281
- 7
- 29
- 64
 
    
    
        Sadeq Shajary
        
- 427
- 6
- 17
- 
                    possible duplicate of [How to split a String in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – RomanK Mar 16 '15 at 12:44
- 
                    This question has no language tag. – MuertoExcobito Mar 16 '15 at 12:52
- 
                    Romank , this is not duplicate. muerto thanks. i added it. – Sadeq Shajary Mar 16 '15 at 12:54
- 
                    1can i use subString method for my purpose? – Sadeq Shajary Mar 16 '15 at 12:56
- 
                    Requires the use of a library, but try: http://stackoverflow.com/a/2298477/580556 – Will Tate Mar 16 '15 at 18:14
- 
                    This is not a duplicate of how to split a string in java, that earlier one is about splitting around a particular character. – James Kingsbery Mar 16 '15 at 20:44
1 Answers
1
            Simplest way is to find the total split strings, and then inchworm up through the values adding the sub-strings to an ArrayList or something. Probably look a lot like this:
int splits = myString.length()/divisor;
int first = 0;
int second = divisor;
for (int i = 0; i < splits; i++) {
    arrayList.add(myString.substring(first, second));
    first += divisor;
    second += divisor;
}
 
    
    
        Henry
        
- 337
- 1
- 5
- 12