Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

splitting String into substrings  RSS feed

 
ramakrishna ranga
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = "6158"; i have to split this as substrings like 6, 1, 5, 8, 61, 15, 58, 615, 158, and 6158. Here is my code

code:
--------------------------------------------------------------------------------


String s = "6158";
for(int i=0;i<s.length();i++)
{
System.out.println(s.charAt(i));
}
int i=0;
int l=1;
while(i<s.length()){
while(l<=s.length()){
System.out.println(s.substring(i,l));
l++;
}
i++;
}

--------------------------------------------------------------------------------

Output: 2 3 1 9 2 23 231 2319 But i am not able to get the all the values, i have tried lot of ways. please any one help me how to get it.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!