Search code examples
java-me

Alternatives to List<object> in j2me?


How can I create a collection in java me?

I need something like List<Customer> customerList=new List<Customer> , but List do not exist in java me (at least not in this way)

I tried using Hashtables that supposedly can contain Objects , but when I retrieve a value, the return value is null:

c = (Customer) htCustomer.get(key)

I could use customerList[] = Customer[20], but arrays need a size and how am I supposed to know the number of items right from the start??

So the question is , what can I use if I need a list of custom objects in java me?? Something that can grow to accommodate new items.

Thanks in advance.


Solution

  • The closest you can get is java.util.Vector:

    Vector customerList = new Vector();
    customerList.addElement(new Customer(...));
    Customer c = (Customer)customerList.elementAt(0);