Development Java

java double split to String[ ][ ]

I’m having a problem coming up with a way to take a string and use .split() twice to make a nested array.

For example if I have the string 1|2|3#1|2 and then I use split("#"), I end up with: [ "1|2|3" , "1|2" ].

I then want to .split("|") the inside strings somehow, so I end up with: [ [1,2,3] , [1,2] ].

But it needs to be a String[][].

I already tried using an ArrayList as the as the external one so I had an ArrayList and then just used .add() to build it up with each of the internal arrays.

But then I could not figure out how to convert it to a String[][].

I’m probably missing something obvious but I’ve been trying for around an hour and have had no luck.

Leave a Reply

Your email address will not be published. Required fields are marked *