1. Stack
- LIFO(Last In First Out)구조의 자료구조를 갖는 클래스
ex> st에 객체 세개를 저장하고(push메소드) 세개 객체를 꺼내오세요.(pop메소드)
import java.util.Stack;
class Test01_stack{
public static void main(String[] args)
{
Stack<String> st=new Stack<String>();
//public E push(E item)
//요소 저장하기
st.push("하나");
st.push("두울");
st.push("세엣");
//저장된 요소의 갯수 얻어오기
int size=st.size();
for(int i=0;i<size;i++){
//마지막에 저장된 요소순으로 꺼내오기
String str=st.pop();
System.out.println(str);
}
}
}
2. TreeSet
ex> TreeSet객체에 값넣고 출력하기.
package test01.util;
import java.util.Iterator;
import java.util.TreeSet;
public class Test02_TreeSet
{
public static void main(String[] args)
{
//TreeSet은 정렬기능을 갖고 있다.
TreeSet<String> ts=new TreeSet<String>();
ts.add("홍길동");
ts.add("김철수");
ts.add("유관순");
Iterator<String> it=ts.iterator();
while(it.hasNext())
{
String str=it.next();
System.out.println(str);
}
}
}
'JAVA' 카테고리의 다른 글
자료구조 - ArrayList / 제네릭 클래스 / 확정for 문 (0) | 2014.09.12 |
---|---|
자료구조 - Map (0) | 2014.09.12 |
자료구조 API - Collection 프레임워크 (0) | 2014.09.12 |
자료구조 API - 제네릭(Generic) (0) | 2014.09.12 |
자료구조 API - Vector 클래스 (0) | 2014.09.12 |