Results 1 to 7 of 7

Thread: List of objects

  1. #1
    rekha is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Question List of objects

    hi,

    List routeObjList =new ArrayList();

    this list should be a list of objects of class Route.How should I cast this list to the object of class route.Plz any one help.and I should not cast like this

    List<Route> routeObjList =new ArrayList<Route>();

    Tell mw any other way.please

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    444
    Rep Power
    6

    Default

    Did You use List in your application?
    Using List we can store Object ,Then why do you need casting?
    Mak
    (Living @ Virtual World)

  3. #3
    rekha is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    hi,

    routeObjList.get(0).locationId

    if I use statements like this it is not accepting where locatioIid is attribute of class route.

  4. #4
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    444
    Rep Power
    6

    Default

    by add() function you can add it...
    Did You try it ReKha.
    Mak
    (Living @ Virtual World)

  5. #5
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    444
    Rep Power
    6

    Default Sample

    ArrayList<emp> Obj=new ArrayList<emp>;
    Obj.add(new emp());


    Simple syntax for store object in arraylist,It works quite well.
    Mak
    (Living @ Virtual World)

  6. #6
    rekha is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    hi,

    ((Route)objList.get(0)).locationid

    this casting is working properly.Thank you for your reply.

  7. #7
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    444
    Rep Power
    6

    Default

    As for me,casting is not a good practice for good programmers.Casting is a shortest way to solve big problem.So,Don't use casting in Application.
    Thanking You.
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  2. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  3. Two Objects
    By losintikfos in forum New To Java
    Replies: 3
    Last Post: 11-14-2008, 07:04 PM
  4. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 12:23 PM
  5. Getting objects from a list
    By markyoung1984 in forum New To Java
    Replies: 4
    Last Post: 03-13-2008, 10:45 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
  •