java中的二维字符串数组

我是java的新手,请帮我解决这个问题。
我有一个字符串可以说

adc|def|efg||hij|lmn|opq 

现在我拆分这个字符串并使用它将其存储在一个数组中

 String output[] = stringname.split("||"); 

现在我再次需要根据’|’拆分 我需要类似的东西

arr[1][]=adc,arr[2][]=def
等等,以便我可以访问每个元素。 类似于二维字符串数组的东西。 我听说这可以使用Arraylist完成,但我无法弄明白。 请帮忙。

这是您的解决方案,除了名称[0] [0] =“adc”,名称[0] [1] =“def”等等:

 String str = "adc|def|efg||hij|lmn|opq"; String[] obj = str.split("\\|\\|"); int i=0; String[][] names = new String[obj.length][]; for(String temp:obj){ names[i++]=temp.split("\\|"); } List yourList = Arrays.asList(names);// yourList will be 2D arraylist. System.out.println(yourList.get(0)[0]); // This will print adc. System.out.println(yourList.get(0)[1]); // This will print def. System.out.println(yourList.get(0)[2]); // This will print efg. // Similarly you can fetch other elements by yourList.get(1)[index] 

你能做的是:

 String str[]="adc|def|efg||hij|lmn|opq".split("||"); String str2[]=str[0].split("|"); str2 will be containing abc, def , efg // arrays have toList() method like: Arrays.asList(any_array); 

难以理解你的问题……

我想你可能想要使用2维的ArrayList: ArrayList>

 String input = "adc|def|efg||hij|lmn|opq"; ArrayList> res = new ArrayList>(); for(String strs:input.split("||")){ ArrayList strList = new ArrayList(); for(String str:strs.split("|")) strList.add(str); res.add(strList); }