0
import java.util.*;
public class PersonList{
public static void arraylist() {
// create an array list
ArrayList Employee = new ArrayList();
// add elements to the array list
Scanner input = new Scanner (System.in);
System.out.println("Name: ");
Employee.add(input.next());
System.out.println("Year of birth: ");
Employee.add(input.next());
System.out.println("");
Employee.add(input.next());
System.out.println("");
Employee.add(input.next());
System.out.println("");
Employee.add(input.next());
System.out.println("Contents of al: " + Employee);
}
}
我有一个用户输入数据的数组列表,我需要将具有空格的数据存储到一个块中。根据条件对ArrayList数据进行排序和排序
我还没有添加其他东西,我将包括。我希望能够在名称中加入诸如“John Smith”之类的名称,而不是在两个单独的块中打印John,Smith。我对编程非常陌生,如果它很sl and和/或令人讨厌,我很抱歉。
使用'input.nextLine()' – Eran
这么简单!谢谢。 –
另外,调用你的'Employee'变量'employee'来遵守命名约定并摆脱那些可怕的原始类型。 – bcsb1001