I looking for simple byte FiFo buffer. I have to put and get or a single byte or array. But I can put every time single byte and get array and vice versa.
Any idea or example code to help me ?
You can use a LinkedList as a queue:
Queue<String> qe=new LinkedList<String>();
qe.add("b");
qe.add("a");
qe.add("c");
qe.add("e");
qe.add("d");
Iterator it=qe.iterator();
System.out.println("Initial Size of Queue :"+qe.size());
while(it.hasNext())
{
String iteratorValue=(String)it.next();
System.out.println("Queue Next Value :"+iteratorValue);
}
// get value and does not remove element from queue
System.out.println("Queue peek :"+qe.peek());
// get first value and remove that object from queue
System.out.println("Queue poll :"+qe.poll());
System.out.println("Final Size of Queue :"+qe.size());
If you also want to add priorities you can use a PriorityQueue
If you need it to be thread safe use ConcurrentLinkedQueue
Also, as @Leonidos says, you can use a ByteBuffer is you need low level I/O, but be careful.
Feel free to comment on the post if you need any clarifications on how to use them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With