java - How to add number of String values to an ArrayList? -
i have scenario wherein have bean class i'm getting client names , other client related details. i'm creating bean object , getting details.
arraylist<clientbean> clientlist = (arraylist<clientbean>) (new queriesdao()) .getallclient();
from above code getting details of client. , client names i'm through index form,
clientbean clist = clientlist.get(2); (clientbean clientbean : clientlist) { clientbean.getclientname(); // here i'm getting client names 1 one. }
my question how add client names in arraylist dynamically?
generally add values list
(so arraylist
) can use methods:
add(e e)
add element @ end of listadd(int index, e element)
add element in specified positionaddall(collection<? extends e> c)
add element @ end of listaddall(int index, collection<? extends e> c)
add element starting specified position
please check documentation (linked on answer) details on each method.
to add client names list (i assumed name string
, change type)
list<string> names = new arraylist<string>(); (clientbean clientbean : clientlist) { names.add(clientbean.getclientname()); } // here names list requested names
Comments
Post a Comment