• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Arraylist retrieval of objects

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
While retrieving objects from the ArrayList after storing them, will they be returned in the SAME ORDER ALWAYS? Are there any particular reasons for the same?
Thanks,
Sam.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
objects are retrived in the same order as it was stored.
because when storing object in the container(arraylist) internally reference code is created in sequential basis which will be used during retrive. one more reason, arraylist is not synchronized.
thanks,
velmurugan.v
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are there any particular reasons for the same?


Classes in the java "collections" API are characterized by the interfaces they implement. Take a look at the JavaDocs for ArrayList.
You will find that it implements List - this requires it to keep references in a strictly defined order.
The way to understand the collections API is by understanding the interfaces.
Bill
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic