LinkedList重写类LinkList.java:
import java.util.LinkedList;import java.util.List;public class LinkList { private static LinkedList <LinkListInfo> linklist = new LinkedList<LinkListInfo>(); public static void addToList(LinkListInfo displayinfo){ linklist.add(displayinfo); } public static void addFistToList(LinkListInfo displayinfo){ linklist.addFirst(displayinfo); } public static void addLastToList(LinkListInfo displayinfo){ linklist.addLast(displayinfo); } public static void removeFistToList(){ linklist.removeFirst(); } public static void removeLastToList(){ linklist.removeLast(); } public static List getList(){ return linklist; }}
K-V信息类LinkListInfo.java:public class LinkListInfo { private String IdName; private int IdNum; public String getIdName() { return IdName; } public void setIdName(String idName) { IdName = idName; } public int getIdNum() { return IdNum; } public void setIdNum(int idNum) { IdNum = idNum; }}
应用测试StorageTest.java:public class StorageTest { public void storageTest (){ for(int i=0;i<10;i++){ LinkListInfo linklistinfo = new LinkListInfo(); linklistinfo.setIdName("SR"+i); linklistinfo.setIdNum(i); LinkList.addToList(linklistinfo);//静态方法类可以直接使用 } } }
测试主类MainTest.java:import java.util.List;public class MainTest { public static void main(String[] args){ StorageTest storagetest = new StorageTest(); storagetest.storageTest(); List<LinkListInfo> linklistinfo = LinkList.getList(); for(int i=0;i<linklistinfo.size();i++){ System.out.println(linklistinfo.get(i).getIdName()); System.out.println(linklistinfo.get(i).getIdNum()); System.out.println(".........."); } }}
打印内容:
SR00..........SR11..........SR22..........SR33..........SR44..........SR55..........SR66..........SR77..........SR88..........SR99..........