Null Pointer Exception. 아마 자바를 사용하면서 많이 보게 되는 에러중에 하나일 것이다. 자바에서는 거의 모든 것들이 레퍼런스이기 때문에, 거의 모든 것들이 null이 될 가능성이 있다. 따라서 항상 null을 확인할 필요가 있다. (기존에는) //User.java public class User { public static User EMPTY = new USER(0, ""); private int age; private String name; public User(int age, String name) { this.age = age; this.name = name; } } //Main.java public class Main { public static void main(String[..
Iterator는 여러 데이터의 묶음을 풀어서 하나씩 처리할 수 있는 수단을 제공한다. iterator.next()를 통해서 다음 데이터를 조회할 수 있다. 다음 데이터를 읽을 수 있지만, 이전 데이터를 읽을 수는 없다. Iterator를 사용하면서 데이터들에 대해 map이나 filter를 적용할 수는 없다. //Main.java public class Main { public static void main(String[] args) { List list = Arrays.asList("A", "AB", "ABC", "ABCD", "ABCDE"); Iterator iter = list.iterator(); while (iter.hasNext()) System.out.println(iter.next()); ..
여러 데이터의 묶음을 컬렉션이라고 한다. Collection List LinkedList ArrayList Set HashSet SortedSet TreeSet Map은 Collection Interface에 포함되지 않는다. Map Hashtable HashMap LinkedHashMap SortedMap TreeMap 메소드 체이닝 예제 //MyCollection.java public class MyCollection { private List list; public MyCollection(List list) { this.list = list; } public MyCollection map(Function function) { // T타입으로부터 U타입을 만드는 function을 인자로 받는다. //..