Sunday, 15 July 2012

java - What is the best way to list all the name in List from List -



java - What is the best way to list all the name in List<String> from List<MyData> -

suppose have class mydata.

public class mydata(){ private string name; private int age; }

now list having 100 mydata objects , want extract names , prepare new list:

list<string> namelist;

what best way that?

this best option:

for (mydata mydata : mydatalist){ namelist.add(mydata.name); }

java arraylist collections

No comments:

Post a Comment