[英]How would I create a LinkedList, then create a value from input. Then if input matches value in LinkedList return that value?
[英]How can I add the value I created from user input and transfer that to a LinkedList?
以下是我创建的以下代码。 我的问题是如何创建一个返回从用户输入创建的值的方法,然后将该值放在我的LinkedList的末尾? 例如,计算机将提示我输入字符“ a”以添加另一个客户端。 如何创建将添加的客户信息存储在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.