Results 1 to 2 of 2
  1. #1
    gapper is offline Member
    Join Date
    Jan 2008
    Posts
    17
    Rep Power
    0

    Default Getting object type

    I have an arraylist with String, int and Date objects in it. I want to display the contents of the arraylist along with the object types of those contents.

    Java Code:
    		ArrayList a1 = new ArrayList();
    		a1.add("Honda");
    		a1.add("Toyota");
    		a1.add(2);
    		a1.add(new Date());
    Expected output:
    Java Code:
    Honda - String
    Toyota - String
    2 - int
    Sun Jan 20 07:50:28 CET 2008 - Date
    Please advice.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Examine this.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 03:12 AM
  2. List views, a type of object
    By Leprechaun in forum New To Java
    Replies: 2
    Last Post: 02-06-2008, 04:07 AM
  3. Need help with creating array of type object
    By riz618 in forum New To Java
    Replies: 3
    Last Post: 01-29-2008, 07:14 AM
  4. How to cast an Object into a specific type (Integer/String) at runtime
    By mailtogagan@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 12-03-2007, 02:04 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 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
  •