I like to convert string for example :
String data = "1|apple,2|ball,3|cat";
into a two dimensional array like this
{{1,apple},{2,ball},{3,cat}}
I have tried using the split("") method but still no solution 🙁
Thanks..
Kai
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Pretty straightforward except that
String.splittakes regex, so metacharacter|needs escaping.See also
Arrays.deepToStringandArrays.deepEqualsfor multidimensional arraysAlternative
If you know how many rows and columns there will be, you can pre-allocate a
String[][]and use aScanneras follows: