我有三個列表,即,列表1,列表2,項目list3我的代碼工作中得到以下表輸出的罰款: O/P如何通過在Java中迭代3個不同的列表對象將元素添加到列表對象?
Getting the list1 objects [man, animal, jackel]
Getting the list2 objects [1, 2, 3]
Getting the list3 objects [bobby, lion, dilip]
現在我試圖讓list4作爲[man,1,bobby]
也list5爲[man,1,bobby , animal,2,lion , jackel,3,dilip]
這裏是我的代碼,這給列表1,列表2的輸出,項目list3
List<String> list1 = new ArrayList<String>();
List<String> list2 = new ArrayList<String>();
List<String> list3 = new ArrayList<String>();
String splitstring="man,animal,jackel";
String splitid="1,2,3";
String splitscreenname="bobby,lion,dilip";
String[] arrsplitstring=splitstring.split(",");
String[] arrssplitid=splitid.split(",");
String[] arrsplitedscreenname=splitscreenname.split(",");
List<String> wordList = Arrays.asList(arrsplitstring);
List<String> wordid = Arrays.asList(arrssplitid);
List<String> wordscreenlist = Arrays.asList(arrsplitedscreenname);
for (int i=0;i<wordList.size();i++){
list1.add(wordList.get(i));
}
System.out.println("Getting the list1 objects " +list1);
for(int i=0;i<wordid.size();i++){
list2.add(wordid.get(i));
}
System.out.println("Getting the list2 objects " +list2);
for (int i=0;i<wordscreenlist.size();i++){
list3.add(wordscreenlist.get(i));
}
System.out.println("Getting the list3 objects " +list3);
我被每個列表的迭代嘗試它對象,但我幾乎找不到解決方案。
在此先感謝
最佳的解決辦法是有一個'Object'將包含所有三個屬性,只有一個'List'這隻會包含這個「Object」的類型。 – SomeJavaGuy