그래서 임의의 전화 번호를 만드는 프로그램을 만들고 있습니다. 이 전화 번호 중 ArrayList
을 만들었으므로 내 ArrayList
을 검색하여 번호 (있는 경우)를 찾고 색인과 해당 데이터를 모두 인쇄 할 수 있기를 원합니다. 여기색인을 인쇄하거나 ArrayList에있는 항목의 항목을 가져 오는 방법
는 내가 지금까지 들어 왔 것입니다 : 내가 if 문에 무엇을 수행하는 방법을 알고 싶어
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
}
}
.
감사합니다.
'indexOf (Object)'사용 –