Java 如何创建联系人列表?

Java 如何创建联系人列表?,java,Java,这是我目前的代码: Scanner scanner = new Scanner(System.in); //Scanning all user input // Dialogue System.out.println("Welcome to jAddress!"); System.out.println("Please tell me your name and phone number?"); String personalInfo = scanner.nextLine(); System.

这是我目前的代码:

Scanner scanner = new Scanner(System.in); //Scanning all user input

// Dialogue
System.out.println("Welcome to jAddress!");
System.out.println("Please tell me your name and phone number?");
String personalInfo = scanner.nextLine();
System.out.println("So your name & number is " + personalInfo);

//-----------------------------------------------------------------------------
String[] theList; // setting the type and name of the Array
theList = new String[6];// giving the array account of how many

/*Inputting the Name & Number Of Each Individual and storing it*/
personalInfo = theList[0]; // This one stores your personalInfo into theLis[0]

System.out.println("Do you Have a Name & Number You'd Like to Input? y/n");
String yesNo = scanner.nextLine();
String y = "yes"; String n = "no";
if(yesNo == y){
    System.out.println("Yay:D");
}else if(yesNo == n){
    System.out.println("GoodBye");
    //break;
}

System.out.println("Please Enter Name & Phone Number:");
theList[1] = scanner.nextLine(); //Storing Number & Name for theList[1]

System.out.println("Please Enter Name & Phone Number:");
theList[2] = scanner.nextLine(); //Storing Number & Name for theList[2]

System.out.println("Please Enter Name & Phone Number:");
theList[3] = scanner.nextLine(); //Storing Number & Name for theList[3]

System.out.println("Please Enter Name & Phone Number:");
theList[4] = scanner.nextLine(); //Storing Number & Name for theList[4]

System.out.println("Please Enter Name & Phone Number:");
theList[5] = scanner.nextLine(); //Storing Number & Name for theList[5]

System.out.println("If you want to access any name simply Press 0-5.");
int chooseContact = scanner.nextInt();
我设法将这两个数组链接到用户输入中。因此,用户可以手动输入姓名和电话号码作为
字符串
,然后将其存储在其中一个数组中

但是,我希望最后的用户能够搜索数组并让它打印姓名和电话号码。例如,我希望用户输入
1
,然后输出数组
列表[0]
编号和名称


我该怎么做?我正在寻找一种实现这一点的简单方法,例如分配变量等。

您只需使用用户输入的索引(+/-一个,取决于0-5/1-6编号的情况)列表[索引]

Nooooooo。。。。不要使用
==
来比较Java中的字符串:(…使用
equals
…列表[chooseContact]这是除了Maroun和fmodos的建议之外,您可能还想看看我不知道您通过索引引用的是什么?我对java还是相当陌生,所以我有点困惑。索引是一种方法吗?任何好的解释都很好,谢谢:Dwell'index'是[]之间使用的数字这些括号,例如列表[1]的索引是“1”,因此如果用户要求第5个值,该值将存储在列表[5]中