1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public class Test {
public static void main(String args[]) throws Exception {
String test = "[ab,cdef,[ghijk],[l,[aa,oo],mno,p],rstuv,wxyz]";
List<Object> list = new ArrayList<Object>();
test = test.substring(1);
test = test.substring(0,test.length()-1);
test(list,test);
System.out.println(list);
}
private static void test(List<Object> list,String s) {
if(s.startsWith("[")) {
ArrayList<Object> sl = new ArrayList<Object>();
list.add(sl);
s = s.substring(1);
s = s.substring(0,s.length()-1);
test(sl,s);
} else {
String[] cut = s.split(",");
list.addAll(Arrays.asList(cut));
}
}
} |
Partager