Search code examples
javalistarrayliststring-parsing

Convert comma separated string into several lists and ignore first 5 characters of string's first element Java


I'm pretty new in Java and now i have following problem which I'm trying to solve.

I have a string like this:

item1item2,item3,item4item5,item6,item7

and what i need to get is this 2 lists:

{item2,item3,item4}
{item5,item6,item7}

Please note that item1 is being omitted in this list and also there's no comma between item4 and item5

Thanks in advance


Solution

  • It would probably be easiest to first split this into two strings using the subString() method, the first containing items 2, 3, 4 and the second 5, 6, 7. Then after that you can use String.split() to get what you want.