我已經創建了兩個數組。我加了起來。然後,我希望通過定義一個方法來打印出新的陣列。但該方法無法打印數組。我的代碼中的錯誤在哪裏?ArrayList的不打印出來
package stringpractice;
import java.util.LinkedList;
import java.util.List;
public class StringPractice {
public static void main(String[] args) {
String[] boy = {"John", "Russel", "Ryan"};
List<String> l1 = new LinkedList<String>();
for (String x : l1) {
l1.add(x);
}
String[] girl = {"Sara", "Leena", "Emilia"};
List<String> l2 = new LinkedList<String>();
for (String y : l2) {
l2.add(y);
l1.addAll(l2);
l2 = null;
printMe(l1);
/*removeStuff(l1, 1,2);
reverseMe(l1);
*/
}
}
public static void printMe(List<String> l1) {
for (String p : l1) {
System.out.printf("%s ", p);
}
System.out.println();
}
}
確切地說,它有幫助。 – SomeOneSomewhere 2014-09-22 11:33:11