java - Using delimiter to organize a set -


is there way use delimiter every other time delimiter symbol comes up?

for example, have set of strings separated commas so: (yes, 2, my, 15, face, 9) want word paired number following it, , separate above set following: ((yes, 2), (my, 15), (face, 9)). using custom list this, in realty add each element [ex. (yes, 2]) list.

you can use regex pattern. code describes solution (since don't know how want store it, printing out).

string data = "yes,2,my,15,face,9";  pattern p = pattern.compile("[^,]*,[^,]*,?"); matcher matcher = p.matcher(data);  while (matcher.find()) {     string[] splitted = matcher.group().split(",");     system.out.println(splitted[0]);     system.out.println(splitted[1]);     system.out.println("******************"); } 

this outputs :

yes 2 ****************** 15 ****************** face 9 ****************** 

another solution use scanner delimiter "," , pair returned parts.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -