我正在尝试创建客户。我正在尝试将每个用户输入添加到 arrayList 中,并使其在最后输出。但是,我的输出给了我一些内存位置。有人可以对此有所了解吗?
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter First Name: ");
String firstName = input.nextLine();
System.out.println("Enter Last Name: ");
String lastName = input.nextLine();
System.out.println("Enter Home Address: ");
String homeAddress = input.nextLine();
Customer cus = new Customer(firstName, lastName, homeAddress);
System.out.println("\nWelcome: ");
System.out.print(cus.getFirstName() + cus.getLastName());
System.out.println("\n Your Shipping Address: ");
System.out.print(cus.getHomeShippingAddress());
List<Customer> customer = new ArrayList<Customer>();
customer.add(cus);
// Output the list contents
printList(customer);
}
public static void printList(List<Customer> list) {
System.out.println("Customers: ");
for (Customer customer : list) {
System.out.printf("%s", customer);
}
System.out.println();
}
}