database - Java creating a roster of unknown size -


i'm posting pick brain kind of question. array appropriate type of data holder roster of unknown size?

i looking create small class 3 methods

  1. addtoroster //which add name proposed array taking in array , string.
  2. getroster //which return elements of roster printed console.
  3. remfrroster // take name, cycle through roster , remove if found.

i'm beginner @ java. i've been programming week , looking find out few things. one, appropriate design methodology class? two, arrays preferred method storing roster of strings? lastly, have initialize array definite size or can have change size approaches limits of size initialized to?

thanks, pano

you use arraylist:

arraylist<player> roster = new arraylist<player>();   roster.add(new player(32));   system.out.println(roster.get(0).getage()); 

an arraylist same thing array, it's size can changed. use arraylist if number of players on roster going change while program running. i.e. if going read players in file use array, if going create indeterminate amount of players after program has started, use arraylist.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -