Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Durril Jansen   on Nov 26 In Java Category.

  
Question Answered By: Kristen Chavez   on Nov 26

You can use a function like this for the same

String[] ret = new String[16];
//default capacity. Using a java util class  and then converting to
String[]
//should be a better idea instead of allocation of memory at the start.
int len = token.length();
int i = 0 ;
for(int j = 0, k = 0; k != -1; j = k + len)
{
k = str.indexOf(token, j);
String tempStr = str.substring(j, k == -1 ? str.length() :
k).trim();
if(tempStr.length() > 0 ){
ret[i] = tempStr;
i++;
}
}

Share: 

 

This Question has 7 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on breaking a String into a String[] Or get search suggestion and latest updates.


Tagged: