그래서 "Person"이 기본 클래스 인 "Address", "Job"및 "Person"이라는 세 개의 클래스를 만들었습니다. 나는 이것들을 시험해 본다 :ArrayList에서 생성 된 모든 객체를 저장하는 클래스를 만드시겠습니까?
Address person2Address = new Address(1054, "Pico St", "Los Angeles", "CA", "97556");
Address person2JobAddress = new Address(5435, "James St", "New York", "NY", "56565");
ArrayList<String> person2Phone = new ArrayList<String>();
person2Phone.add("555-555-55");
Job person2Job = new Job("Mechanic", 35000.00, person2JobAddress);
Person person2 = new Person("Rollan Tico", "New York", 'M', person2Address, person2Job, person2Phone);
System.out.println(person2.toString());
그들은 모든 것을 정확하게 인쇄한다. 자, 여기가 내가 붙어있는 곳이야. ArrayList에서 생성 된 각 Person을 저장하는 Persons라는 다른 클래스를 어떻게 만들 수 있습니까? 어떤 constrcunert가있을 것입니까? 나는 Arrayist가 ArrayList<Person> List = new ArrayList<Person>();
에 의해 만들어 졌음을 알고 있지만, 나는 뭔가를 놓치고 있다는 느낌을 받았습니다.
별도의 클래스가 필요하지 않습니다. 당신이 불변의 목록을 찾고 있다고 가정하면'List persons = Arrays.asList (person1, person2, ...); ' –
@JacobG를 사용할 수 있습니다. 'Arrays.asList()'는 고정 크기 일 뿐이며, 변경되지 않습니다. – shmosel