[英]How can I add the value I created from user input and transfer that to a LinkedList?
Below is the following code I have created. 以下是我创建的以下代码。 My question is how can I create a method that returns a value created from user input and then place that value at the end of my LinkedList? 我的问题是如何创建一个返回从用户输入创建的值的方法,然后将该值放在我的LinkedList的末尾? For example the computer will prompt me to enter the char 'a' to add another client. 例如,计算机将提示我输入字符“ a”以添加另一个客户端。 How can I create a method that stores that added client information in the LinkedList? 如何创建将添加的客户信息存储在LinkedList中的方法?
import java.io.*;
import java.util.*;
public class Clients implements Serializable
{
private LinkedList<Person> clients = new LinkedList<Person>();
private int id = 1;
private static Scanner in = new Scanner(System.in);
public static String nextLine()
{
return in.nextLine();
}
public static char nextChar()
{
return in.nextLine().charAt(0);
}
public Clients()
{
clients.add(new Person("Homer", id++));
clients.add(new Person("Marge", id++));
}
public void addClients()
{
//??????????
//????????????
}
}
假设我没有丢失任何东西,也没有验证输入,我想那应该是这样的:
clients.add(new Person(nextLine(), id++);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.