- 通过练习体会封装的思想,通过封装达到我们想要的目的,例如将方法名称改成我们想要的名称
-
- 队列是先进先出 FIFO 如同一个水管
-
-
- package com.mytest;
-
- import java.util.LinkedList;
-
-
- class DuiLie {
-
- private LinkedList linkedList;
-
- public DuiLie() {
- linkedList = new LinkedList();
- }
-
- public void myAdd(Object obj) {
- linkedList.addFirst(obj);
- }
-
- public Object myGet() {
- return linkedList.removeLast();
- }
-
- public boolean isNull() {
-
- return linkedList.isEmpty();
- }
- }
- public class test02 {
-
- public static void main(String[] args) {
-
- DuiLie duiLie = new DuiLie();
-
- duiLie.myAdd("java01");
- duiLie.myAdd("java02");
- duiLie.myAdd("java03");
- duiLie.myAdd("java04");
-
- while (!duiLie.isNull()) {
- System.out.println(duiLie.myGet());
- }
- }
- }
-
复制代码 |
|