ArrayList
LinkList
List the underlying implementation
Node.java (node type)
Package cn.Collection; // used to represent a node public class the Node { the Node Previous; // a node Object obj; the Node Next; // next node public the Node () { } public the Node (the Node Previous, Object obj, Next the Node) { Super (); the this .previous = Previous; the this .OBJ = obj; the this .next = Next; } public the Node GetPrevious () { return Previous; } public void setPrevious(Node previous) { this.previous = previous; } public Object getObj() { return obj; } public void setObj(Object obj) { this.obj = obj; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } }
Test01.java
package cn.Collection; public class Test01 { private Node first; private Node last; private int size; public void add(Object obj) { Node n=new Node(); if(first==null) { n.setPrevious(null); n.setObj(obj); n.setNext(null); first=n; last=n; } else { // to the last node of the new node directly increase n.setPrevious (last); n.setObj (obj); n.setNext ( null ); last.setNext (n-); last = n-; } size ++ ; } public int size () { return size; } public Object GET ( int index) { // 2 // 0,1,2,3,4 the Node TEMP = null ; IF (= First! null ) { TEMP=first; for(int i=0;i<index;i++) { temp=temp.next; } } return temp.obj; } public static void main(String[] args) { Test01 list=new Test01(); list.add("aaa"); list.add("dd"); list.add("d"); System.out.println(list.size()); System.out.println(list.get(1)); } }