Results 1 to 5 of 5
  1. #1
    adela is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Getting value of Object[] in an ArrayList

    Hi all,

    I really need some help, I'm stuck on this for days. Looking on the attached image, I need to get the value of myList[0][3]. Would it be like myList.get(0).<some code here but I don't know what it is>.

    I search the net but don't get any ideas.

    Can somebody give me some hint? Thanks.
    Attached Thumbnails Attached Thumbnails Getting value of Object[] in an ArrayList-mylist-values.jpg  

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Show us the definition of the list, as well as how you assigning data to it, as well as how you are defining what it is you are adding to it.

    Well, if generitised simply
    Java Code:
    myList.get(0)[3]
    if not
    Java Code:
    ((Object[]) myList.get(0))[3]
    assuming it is an Object[] and not a String[] (or something). If it is something more specific than use something more specific.
    Last edited by masijade; 01-27-2011 at 10:43 AM.

  3. #3
    Debugger is offline Member
    Join Date
    Jan 2011
    Posts
    27
    Rep Power
    0

    Default

    what exactly are you trying to get, the information that is in the ArrayList[0] and [3]?

    System.out.println(arrayList.get(0));
    System.out.println(arrayList.get(3));

  4. #4
    adela is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    To Masijade, thanks for your reply your first suggestion produces this error: array required, but java.lang.Object found. But your second suggestion works! Wow great! Thank you very much, you're a genius. I never thought of that.

    To Debugger, thanks also for your reply. I am trying to get the product name value which is assigned to myList[0][3] but I got it now, thanks again to Masijade.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

Similar Threads

  1. Replies: 2
    Last Post: 11-16-2010, 05:51 PM
  2. How to Store ArrayList into an Object?
    By TheGame in forum New To Java
    Replies: 6
    Last Post: 10-10-2010, 10:38 PM
  3. Replies: 3
    Last Post: 03-15-2010, 08:44 PM
  4. Replies: 1
    Last Post: 03-04-2009, 06:14 PM
  5. how to return an object from an arraylist
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •