File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

put value in list at the beginning

 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a ArrayList, when I put a value, the value is put at the end of the list.
How can I put it at the beginning of the list?
Do I have to use a comparator or is there a easier better way?

 
Omar Al Kababji
Ranch Hand
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you took a look at the docs of the java.util.ArrayList here ?? take a look at the several add() methods.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You wouldn't usually use a Comparator with a List. A List "remembers" the order you insert the elements, and if you follow omar al kababji's hint, you can select a different insertion ordering.
A Comparator is used with some Sets so as to order the elements in the order of the elements' "value". Look at Comparator and this Set interface.
 
salvin francis
Bartender
Pie
Posts: 1230
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me give you a hint....


You want to Add an element to the 0th position of an ArrayList

 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay thank you

add(0, Object element)

clearly:-)

thanks!
 
salvin francis
Bartender
Pie
Posts: 1230
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic