gnu

블로그 이미지
by 군우

TAG CLOUD

  • Total hit
  • Today hit
  • Yesterday hit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package framework22;
 
import java.util.LinkedList;
 
public class MainTest2 {
 
    public static void main(String[] args)
    {
        LinkedList<String> link = new LinkedList<String>();
        
        for(int a = 0;a<10;a++)
            link.add(a,"test "+(a+1));
        for(int a = 0;a<link.size();a++)
        System.out.println(link.get(a));
    }
}
cs



제네릭으로 linkedList 만듬


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package framework22;
 
class Box<T>
{
    T item;
    public Box<T> next;    // 다음인스턴스 자체를 가리키는 거 만듬
    public void inputStore(T item, Box<String> box1)
    {
        this.item = item;
    }
}
 
public class makeLinkedList {
    public static void main(String[] args)
    {
        Box<String> box1 = new Box<String>();
        box1.next = new Box<String>();
        box1.next.next = new Box<String>();
        box1.next.next.next = new Box<String>();
        
        box1.inputStore("The first", box1);
        box1.next.inputStore("Secend", box1.next);
        box1.next.next.inputStore("Third", box1.next.next);
        box1.next.next.next.inputStore("Fourth"null);  // 마지막
        
        System.out.println("first : "+ box1.item);
        System.out.println("second : "+ box1.next.item);
        System.out.println("third : "+ box1.next.next.item);
        System.out.println("fourth : "+ box1.next.next.next.item);
    }
}
cs


'Java > Java Concept' 카테고리의 다른 글

[Java] TreeSet<E>  (0) 2018.03.13
[Java] HashSet, hash 알고리즘,  (0) 2018.03.12
[Java] framework Arraylist  (0) 2018.03.12
[Java] 제네릭클래스의 와일드카드 이용하기.  (0) 2018.03.12
[Java] 제네릭 클래스  (0) 2018.03.10
AND

ARTICLE CATEGORY

분류 전체보기 (197)
C (0)
HTML (7)
C# (88)
Python (27)
IT (0)
Android (2)
Java (65)
Study (5)
JavaScript (1)
JSP (2)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

ARCHIVE

LINK