Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Tokenizing a string with multiple delimiters

843789Feb 25 2010 — edited Feb 26 2010
Part of my program has a tree like data-structure stored in a HashMap who's keys can be written out as a string. This will produce something like this:

[ (0,0) [ (1,0) [ (2,0) (2,1) (2,2) (2,3) ] (1,1) [ (2,4) ] (1,2) [ (2,5) (2,6) (2,7) (2,8) ] (1,3) [ (2,9) (2,10) (2,11) (2,12) ] ]

Which preserves the tree structure by using [and ] to denote that the coords contained within are children of the coordinates preceding the brackets, with individual coordinates falling between parenthesis and x/y separated by a comma. The problem I am having is in parsing this back into a data-structure that still retains the tree structure. I've used StringTokenizer before but that was with a simple csv file with a single delimiter.I am looking to parse it back into an array of arrays, with each array containing an array of it's children, but am unsure how this can be achieved given the multiple delimiters. I had originally planned to tokenize on each individual token but cant figure out how. I was wondering if there was perhaps an easier way of doing things? I can change the format of the string easily so if anyone can think of a more logical or efficient way of doing things then do tell.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2010
Added on Feb 25 2010
16 comments
629 views