I wanted to substring a String depending on int that I will passed on the method. I used nested loop for this. But everytime it loops I wanted to substring only from last substring to int the I passed in the method and get also the last string. How can I achieve this?
private static void input(String s, int I)
{
List list = new ArrayList();
for(int a = 0; a < s.length(); a++)
{
for(int position = 0; position < s.length(); position++)
{
if(position + a + I <= s.length())
{
list.add(s.substring(position, position + a + I));
}
}
}
}
input("abaca", 2);
Expected output: "ab", "ac", "a"