日期:2014-05-20 浏览次数:20905 次
String text = "aa$Node5,\nbd$Node5,\ndc$Node21,\nht$Node20,\ngf$Node20,\ncc$Node20,\nui$Node4";
String[] rows = text.split(",\n");
List<Object> result = new ArrayList<Object>();
String node = null;
List<String> values = new ArrayList<String>();;
for (String row: rows){
String[] cols = row.split("[$]");
if(!cols[1].equals(node) && node!=null){
result.add(values.toArray());
values = new ArrayList<String>();
}
values.add(cols[0]);
node = cols[1];
}
result.add(values.toArray());
for(Object row: result){
System.out.println(Arrays.toString((Object[]) row));
}