0

Is there a Queue or List in GWT in which items are retrieved in the order in which they were added?

E.g I want to be able to do this:

list.add("a");
list.add("b");
list.add("c");

for (String s: list)
{
   Window.alert( s);
} 

and for the output to always say: a, b, c and never c, a, b or any other order. Is that possible?

I see on the JRE emulation page that PriorityQueue is implemented, however the documentation for that says that the items are ordered in their natural order. I'm not sure what exactly that means, if it means FIFO (first in first out), or some other way of ordering.

Ali
  • 261,656
  • 265
  • 575
  • 769

2 Answers2

2

You get this guarantee with any List, including ArrayList. I recommend an ArrayList as it is generally a good idea to use specific implementations in GWT to reduce serialization code. LinkList is another option, and there is a good comparison when to use it instead of ArrayList: When to use LinkedList over ArrayList?

Community
  • 1
  • 1
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • List - An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. (http://docs.oracle.com/javase/7/docs/api/java/util/List.html) – Andrei Volgin Mar 05 '14 at 03:14
  • It is an order in which elements are inserted. Look at the JavaDoc for ArrayList - add(E e) adds an element to the end of the list. – Andrei Volgin Mar 05 '14 at 03:19
2

Natural Order Means that they are sorted based on the default Comparator

Try using a Linked List

jpdymond
  • 1,517
  • 1
  • 8
  • 10