• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList containing array of objects

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an arraylist whose each element is a fixed size array of object

Wwe dont have any API to retrive array of object from ArrayList
and therefore I was wondering who can we retrieve each element as an array
from arraylist

If any one has any idea please help

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is hardly an advanced topic. Just cast from Object to Thing[], or whatever it's an array of:
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


We dont have any API to retrive array of object from ArrayList


We can however retrieve an Object from an ArrayList, and if that Object is an array, we can cast it to an array and use it.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using the latest versions of Java (5+) you shouldn't be messing abouit with casts in the first place. Take all the casting out, and declare your List as generic.becomesTry it and see.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList Program: Learn how to compare two ArrayList in Java
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the comparison method in that blog is incorrect.
  • 1: You are using ArrayLists, when you would be better using the interface List.
  • 2: You are sorting the Lists and destroyinng some of the information they each embody. You are using the Lists more as if they were Sets.
  • 3: Your use of retainAll() looks correct, but you are not finding distinct elements (disjunction) with removeAll(). You are finding an asymmetrical difference.
  •  
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic