For your requriement, you can use a Queue
. Only things once you populated your Queue, you have to first poll()
the value from it and after using the value you need to reinsert the value in Queue
by calling add()
method.
Queue<String> testQueue = new LinkedList<String>();
testQueue.add("first");
testQueue.add("understand");
testQueue.add("problem");
testQueue.add("then Ask");
String fristValue = testQueue.poll();
//Use your value;
System.out.println(fristValue);
//After you are done using it, resubmit it to the Queue
testQueue.add(fristValue);
String secondValue = testQueue.poll();
//same way....
System.out.println(secondValue);
Replace String
to your own encapsulated class if your really use key
. But considering your question, key
is not as important for you.
Anyways if its important, then your encapsulated class would look like below:
class Entry{
String key;
String value;
.....
//Relevant methods.
}