고객 개체에서 값을 선택하여 가져 오려고합니다. 내가하고 싶은 일은 "702312"와 같은 개인 번호를 입력하고 "702312"와 같은 데이터 회원 개인 번호를 가진 고객 객체를 검색하는 것입니다. 그리고 그것을 발견했을 때 나머지 가치를 얻거나 내용을 변경하고 싶습니다. 이 클래스는 Customer 클래스의 고객 객체를 생성 한 다음 arraylist에 저장하는 코드입니다.Java의 arraylist에있는 객체 메소드에서 값을 가져 오겠습니까?
// create a new customer object and send personal number, name and account number to constructor
Customer customer = new Customer(personalNumber, name, newAccountNumber);
// create an arraylist to store customer objects
ArrayList<Customer> customerList = new ArrayList<Customer>();
// add the new customer object to arraylist that holds all customer objects
customerList.add(customer);
이 값에 도달하려고 시도했지만 작동하지 않아 일부 도움이 필요합니까? 나는이 시도
if(customer.getAccountOwnerPersonalNumber() == "702312")...
:
// search for customer
for (Customer customer : customerList) {
if(customer.getAccountOwnerPersonalNumber() == "702312"){
System.out.println("OK!!!");
}
}
그리고 대신
또한 이런 식으로 테스트 한 마지막if(customer.personalNumber == "702312")...
:
for(int i=0;i<customerList.size();i++){
if(customerList.get(i).getAccountOwnerName() == "702312");
System.out.println("OK");
break;
}
아니에요 내가 제대로하고 있는지 확실히!? 도움은 preciated입니다! 감사!
어떤 유형이 .getAccountOwnerName() 함수를 반환합니까? 나는 숫자와 문자열을 비교하려고 노력한다고 생각한다. – Gatekeeper
당신은'System.out.println' 메소드를 올바르게 호출하지 않는다. 'System.out.println ("OK");' – Michael
@ 마이클 : 농담하는거야? – BalusC