목록JAVA 문법 (40)
Super Coding Addict
* TreeSet 클래스 - Tree~ : 객체 정렬에 사용되는 클래스 - 중복을 허용하지 않으면서 오름차순이나 내림차순으로 객체를 정렬 - 예제 # TreeSetTest 클래스 package ch11.treeset; import java.util.TreeSet; public class TreeSetTest { public static void main(String[] args) { TreeSet treeSet = new TreeSet(); treeSet.add("홍길동"); treeSet.add("강감찬"); treeSet.add("이순신"); for(String str : treeSet) { System.out.println(str); } } } --> String은 이미 Comparable을 구현해..
* Iterator로 순회하기 - set의 경우 arrayList와 달리 i번째 요소를 get할 수 없음 (내부적으로 순서대로 저장되어 있지 않기에) => iterator() 메서드 호출! - 모든 Collection 개체의 Iterator() 메서드를 호출하면 Iterator가 반환되며, 이것을 가지고 순회할 수 있음 - 예제 # HashSetTest 클래스 package ch11.set; import java.util.HashSet; import java.util.Iterator; public class HashSetTest { public static void main(String[] args) { HashSet set = new HashSet(); set.add("이순신"..
* Stack 구현하기 - LIFO (Last In First Out) - ArrayList나 LinkedList로 구현할 수 있음 - ex) 최근 자료 가져오기 * Queue 구현하기 - FIFO (First In First Out) - ArrayList나 LinkedList로 구현 가능 - ex) 선착순, 대기열 등 구현 - 예제 # StackTest 클래스 package ch11.collection; import java.util.ArrayList; class MyStack { private ArrayList arrayStack = new ArrayList(); public void push(String data) { arrayStack.add(data); }..
* List 인터페이스 - Collection 하위 인터페이스 - 객체를 순서에 따라 저장하고 관리하는 데 필요한 메서드가 선언된 인터페이스 - ex) ArrayList, Vector ... * ArrayLIst와 Vector - 둘다 객체 배열 클래스 - Vector는 자바2부터 제공된 클래스로 일반적으로는 ArrayLIst를 더 많이 사용한다 - Vector는 멀티 쓰레드 프로그램에서 동기화(synchronization)을 지원한다 - capacity : 배열의 전체 크기 - size : 배열 안에 들어있는 자료의 개수(?) * ArrayList와 LinkedList - 둘다 자료의 순차적 구조를 구현한 클래스 - ArrayList는 배열을 구현한 클래스, 논리적 순서 = ..
* 컬렉션 프레임 워크 - 프로그램 구현에 필요한 자료구조와 알고리즘을 구현해놓은 라이브러리 - java.util 패키지에 구현되어 있음 - 이를 사용하여 개발에 소요되는 시간을 절약하고 최적화된 라이브러리 사용 가능 - Collection인터페이스와 Map인터페이스로 구성됨 * Collection 인터페이스 - 하나의 객체에 대한 자료구조 cf. map : key-value pair(쌍)로 이루어져 있는 객체를 관리 - 하위에 List, Set 인터페이스가있다 * Map 인터페이스 - 쌍(pair)으로 이루어진 객체를 관리하는 데 필요한 여러 메서드가 선언되어 있음 - key-value 쌍으로 이루어져 있으며, key는 중복될 수 없음 * 배열(Array) vs. Linke..
--> Decorator와 실제 Component가 모두 하나의 클래스에서 상속을 받아서 같은 Operation이 제공된다는 것이 중요 --> 우유, 모카시럽, 휘핑크림은 커피가 아닌 데코레이터! # Coffee 추상 클래스 (Component) package Ch14.stream.coffee; public abstract class Coffee { public abstract void brewing(); } --> 여기서 Operation()은 brewing()메서드 # KenyaAmericano 클래스 (Concrete Component) package Ch14.stream.coffee; public class KenyaAmericano extends Coffee{ @Override public vo..