Thanks for the clear explanation. This is exactly what i needed! On Fri, Mar 27, 2009 at 6:57 AM, Streets Of Boston <[email protected]>wrote:
> > You can not create a Collection. It is an interface, as other already > pointed out. > > Judging from your other posts, i'd suggest your using an > ArrayList<Car>. > An ArrayList is basically some behavior around an array of objects (in > your case Car[]). Internally, it's using an array and it handles all > the insertions, removals, etc. for you. To avoid too many object- > allocations, initialize your ArrayList with an appropriate capacity. > E.g. if you think you'll never need more than 100 objects do > "Collection<Car> _cars = new ArrayList<Car>(100);" > > If you want to make your objects searchable, e.g. making this code > work "int idx = _cars.indexOf(someCar);", implement a "public boolean > equals(Object otherCar)" method on your Car class. > > On Mar 26, 9:50 pm, Josh Dobbs <[email protected]> wrote: > > I want to keep track of multiple instances of a class without hardcoding > a > > bunch of variables. I can use either an array or collection it doesnt > really > > matter to me but I cant seem to get either to work. I cant seem to find > an > > example of what I want to do anywhere. Im also open to suggestions if > their > > is a better way to do this. > > > > On Thu, Mar 26, 2009 at 6:34 AM, Stoyan Damov <[email protected] > >wrote: > > > > > > > > > > > > > I don't understand what are you really asking? Whether arrays are > > > faster than collection classes? Yes, they are faster, but you have to > > > manage their contents (insertions, deletions, etc.) yourself. > > > > > On Thu, Mar 26, 2009 at 3:31 PM, Josh Dobbs <[email protected]> > wrote: > > > > Here's what my code looks like... > > > > > > private > > > > > > Collection _cars; > > > > > > Car myCar= > > > > > > new Car(1,1,false,5, "blue"); > > > > > > Car myCar2= new Car(1,1,false,5, "red"); > > > > > > _cars.add(myCar); > > > > _cars.add(myCar2); > > > > > > On Thu, Mar 26, 2009 at 6:18 AM, Josh Dobbs <[email protected]> > wrote: > > > > > >> >You mean like the ones in the java.util > > > >> Yes, specifically java.util.collection > > > >> >What's a VO? > > > >> A VO is basically a class that only contains properties(Value > Objects). > > > > > >> On Thu, Mar 26, 2009 at 4:53 AM, Mark Murphy < > [email protected]> > > > >> wrote: > > > > > >>> Josh wrote: > > > >>> > I want to store objects into an array or collection(whichever is > best > > > >>> > suited to this in dalvik). > > > > > >>> You mean like the ones in the java.util package? > > > > > >>> > the objects are basically just VO's all of > > > >>> > the same class that i want to keep track of. > > > > > >>> What's a VO? > > > > > >>> -- > > > >>> Mark Murphy (a Commons Guy) > > > >>>http://commonsware.com > > > >>> _The Busy Coder's Guide to Android Development_ Version 2.0 > Available!- Hide quoted text - > > > > - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

