Collection인터페이스
collection은 다수의 데이터, 즉 테이터 그룹을 뜻하고 collection 인터페이스는 컬렉션 클래스에 정의된 데이터를 읽고, 추가하고 삭제하는 등 컬렉션을 다루는 가장 기본적인 메서드들을 정의하고 있다.
List인터페이스
Set인터페이스
Map인터페이스
리스트 객체로 만들기
조건
•
90명의 이름의 이름을 배열에 넣기
•
main 메서드에는 실행을 위한 것만 넣어 최소화하기
Names 클래스 : 이름 넣는 함수 생성
import java.util.ArrayList;
import java.util.List;
public class Names {
private List<String> students = new ArrayList<>();
public List<String> makeList() {
this.students.add("권하준");
this.students.add("강수빈");
this.students.add("권하준");
this.students.add("조성윤");
this.students.add("안예은");
this.students.add("남우빈");
this.students.add("최경민");
return students;
}
}
Java
복사
LikeLion2th 클래스 : 이름을 갖고 있는 클래스 만들기
import java.util.ArrayList;
import java.util.List;
public class LikeLion2th {
private List<String> students = new ArrayList<>();
public LikeLion2th() {
Names name = new Names();
students = name.makeList();
}
//이름들이 들어있는 List
public List<String> getStudentList() {
return this.students;
}
}
Java
복사
ListPracticeMain : 메인메서드에서 실행
import java.util.List;
public class ListPracticeMain {
public static void main(String[] args) {
LikeLion2th likeLion2th = new LikeLion2th();
List<String> students = likeLion2th.getStudentList();
for (String student : students) {
System.out.println(student);
}
System.out.println(students.size());
}
}
Java
복사
static과 JVM 이해하기
public class Exercise {
public void plus(int a, int b) {
System.out.printf("%d + %d = %d", a, b, a+b);
}
public static void main(String[] args) {
plus(a, b);
}
}
Java
복사
plus(a, b) 메서드가 실행되지 않는 이유는?