課程
/后端開發
/Java
/Java消息中間件
Java怎么刪除隊列
2017-12-19
源自:Java消息中間件 4-3
正在回答
也可以用split("");去分割,然后進行判斷滾邊上去,你發音是李陽么?不是不要嚎!!!!!
管理頁面里面有delete或者隊列模式下,用消費者消費掉。。。
哦哦,我說的是activemq隊列啊
import java.util.LinkedList;
import java.util.Queue;
import org.junit.Before;
import org.junit.Test;
/**
?* 隊列測試:實現類使用LinkedList
?*?
?* Queue也有很多其他的實現類,比如java.util.concurrent.LinkedBlockingQueue。
?* LinkedBlockingQueue是一個阻塞的線程安全的隊列,底層實現也是使用鏈式結構。
?*/
public class TestQuene {
? ? // 定義一個隊列
? ? Queue<String> queue;
? ? @Before
? ? public void before() {
? ? ? ? // 實例化隊列變量
? ? ? ? queue = new LinkedList<String>();
? ? ? ? // add方法向隊列中添加元素,返回布爾值,add方法添加失敗時會拋異常,不推薦使用
? ? ? ? // queue.add("1");
? ? ? ? // queue.add("2");
? ? ? ? // queue.add("3");
? ? ? ? // queue.add("4");
? ? ? ? // queue.add("5");
? ? ? ? // offer方法向隊列中添加元素,返回布爾值
? ? ? ? queue.offer("a");
? ? ? ? queue.offer("b");
? ? ? ? queue.offer("c");
? ? ? ? queue.offer("d");
? ? ? ? queue.offer("e");
? ? }
? ? // poll方法移除隊列首個元素并返回,若隊列為空,返回null
? ? @Test
? ? public void test1() {
? ? ? ? // 彈出元素
? ? ? ? String pollEle = queue.poll(); // 先進先出,彈出了a
? ? ? ? System.out.println(pollEle); // a
? ? ? ? System.out.println(queue); // [b, c, d, e]
? ? // remove方法移除首個元素并返回,若隊列為空,會拋出異常:NoSuchElementException,不推薦使用
? ? public void test2() {
? ? ? ? String remove = queue.remove(); // 先進先出,彈出了a
? ? ? ? System.out.println(remove); // a
? ? // peek方法返回隊列首個元素,但不移除,若隊列為空,返回null
? ? public void test3() {
? ? ? ? // 查看首個元素
? ? ? ? String peek = queue.peek(); // 首個元素是a,最先加入
? ? ? ? System.out.println(peek); // a
? ? ? ? System.out.println(queue); // [a, b, c, d, e]
? ? // element方法返回隊列的頭元素,但不移除,若隊列為空,會拋出異常:NoSuchElementException,不推薦使用
? ? public void test4() {
? ? ? ? String element = queue.element();
? ? ? ? System.out.println(element); // a
}
舉報
使用Java消息中間件處理異步消息
3 回答Activemq隊列消費端onmessage監聽不到
2 回答消息隊列異步怎么實現的,面試時被問到了,很尷尬
1 回答隊列和主題模式的英文名稱是什么?
2 回答主題模式和隊列模式的區別
5 回答關于那個隊列模式有個問題 ?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2022-03-25
也可以用split("");去分割,然后進行判斷滾邊上去,你發音是李陽么?不是不要嚎!!!!!
2018-03-03
管理頁面里面有delete
或者隊列模式下,用消費者消費掉。。。
2018-01-04
哦哦,我說的是activemq隊列啊
2017-12-29
import java.util.LinkedList;
import java.util.Queue;
import org.junit.Before;
import org.junit.Test;
/**
?* 隊列測試:實現類使用LinkedList
?*?
?* Queue也有很多其他的實現類,比如java.util.concurrent.LinkedBlockingQueue。
?* LinkedBlockingQueue是一個阻塞的線程安全的隊列,底層實現也是使用鏈式結構。
?*/
public class TestQuene {
? ? // 定義一個隊列
? ? Queue<String> queue;
? ? @Before
? ? public void before() {
? ? ? ? // 實例化隊列變量
? ? ? ? queue = new LinkedList<String>();
? ? ? ? // add方法向隊列中添加元素,返回布爾值,add方法添加失敗時會拋異常,不推薦使用
? ? ? ? // queue.add("1");
? ? ? ? // queue.add("2");
? ? ? ? // queue.add("3");
? ? ? ? // queue.add("4");
? ? ? ? // queue.add("5");
? ? ? ? // offer方法向隊列中添加元素,返回布爾值
? ? ? ? queue.offer("a");
? ? ? ? queue.offer("b");
? ? ? ? queue.offer("c");
? ? ? ? queue.offer("d");
? ? ? ? queue.offer("e");
? ? }
? ? // poll方法移除隊列首個元素并返回,若隊列為空,返回null
? ? @Test
? ? public void test1() {
? ? ? ? // 彈出元素
? ? ? ? String pollEle = queue.poll(); // 先進先出,彈出了a
? ? ? ? System.out.println(pollEle); // a
? ? ? ? System.out.println(queue); // [b, c, d, e]
? ? }
? ? // remove方法移除首個元素并返回,若隊列為空,會拋出異常:NoSuchElementException,不推薦使用
? ? @Test
? ? public void test2() {
? ? ? ? // 彈出元素
? ? ? ? String remove = queue.remove(); // 先進先出,彈出了a
? ? ? ? System.out.println(remove); // a
? ? ? ? System.out.println(queue); // [b, c, d, e]
? ? }
? ? // peek方法返回隊列首個元素,但不移除,若隊列為空,返回null
? ? @Test
? ? public void test3() {
? ? ? ? // 查看首個元素
? ? ? ? String peek = queue.peek(); // 首個元素是a,最先加入
? ? ? ? System.out.println(peek); // a
? ? ? ? System.out.println(queue); // [a, b, c, d, e]
? ? }
? ? // element方法返回隊列的頭元素,但不移除,若隊列為空,會拋出異常:NoSuchElementException,不推薦使用
? ? @Test
? ? public void test4() {
? ? ? ? // 查看首個元素
? ? ? ? String element = queue.element();
? ? ? ? System.out.println(element); // a
? ? ? ? System.out.println(queue); // [a, b, c, d, e]
? ? }
}