标签:display size style stat 信息 静态方法 重写 add fir
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("..........");
}
}
}
打印内容:
SR0
0
..........
SR1
1
..........
SR2
2
..........
SR3
3
..........
SR4
4
..........
SR5
5
..........
SR6
6
..........
SR7
7
..........
SR8
8
..........
SR9
9
..........
标签:display size style stat 信息 静态方法 重写 add fir
原文地址:https://www.cnblogs.com/Sky-Raining/p/10279577.html