1. HUGE Androidforums.com UPDATE! Learn what's new (and download the new app!)
    Dismiss Notice

Question on objects in array.

Last Updated:

  1. LeonR

    LeonR Member This Topic's Starter

    Feb 22, 2010
    Likes Received:

    I'm new at java, so please excuse my terminology!

    I also cant remember the exact code off the top of my head, so you will have to guess what I mean if its wrong :D

    Basically I want to create multiple objects of the same class, but I also want to keep a reference/track to each one. What would suit me, and what seems to work is if I create an (object array?) array.. such as...

    MyClass myObj[] = new MyClass[10]; << is that right?

    And then I can create them like

    myObj[0] = new MyClass();


    Again I apologise for the code, its a steep learning curve for me as i'm more used to .net, and even then I dont implement classes and objects like java.

    Is it an acceptable way to manage/use multiple objects in this manner? It's not considered bad practice?

    For example, I might want to create a few objects, but keep referencing each one from another thread, so I would need to be able to call each one individually and it seems from what im trying to do, an array of objects would work best?

    Cheers! :cool:

  2. alostpacket

    alostpacket Over Macho Grande? VIP Member

    Nov 29, 2009
    Likes Received:
    Looks ok to me, you can also use a typed array list

    ArrayList<MyClass> myList = new ArrayList<MyClass>();

    myList.add( new MyClass() );

    myList.get( 0 ).myMethodFromMyClass();

Share This Page