所以我正在制作一个生成随机电话号码的程序。我已经制作了ArrayList
这些电话号码中的一个,我希望能够搜索ArrayList
并找到该号码(如果存在)并打印它的索引和包含的数据。
这是我到目前为止所得到的:
public static ArrayList<String>phoneList = new ArrayList<String>();
public static void main(String[] args)
{
Scanner s = new Scanner();
for(int i = 0; i < 10; i++){
phoneList.add(getPhoneNumber()); //getPhoneNumber returns a random phoneNumber
}
System.out.print("Enter Phone Number: ");
String enteredNumber = s.nextLine();
if(phoneList.containts(enteredNumber)){
//tell me the index of that phone number in the list and
//print out the phone number
}
}
我想知道如何执行 if 语句中的内容。
谢谢!