java - Iterate Generic type<User> of ArrayList -


i trying values arraylist.

i have user type bean class below..

class user{        public string link;       public string url;       user(string l,string u){            this.link=link;            this.url=url;       } setters , getters below..  

here trying write class main.

public class listclass{       public static void main(string args[]){             list<user> list = new arraylist<user>();             list.add(new user("link1","url1"));             list.add(new user("link2","url2"));             list.add(new user("link3","url3"));              //here want iterate both links , urls 1 one               iterator it=list.iterator();             // remaining code both link1 , url1 .. } 

i need output as:

link1  url1 link2  url2 link3  url2 

you can use for-in construct instead of iterator:

for (user u : list) {   system.out.println(u.link + " " + u.url); } 

if want use iterator:

iterator<user> it=list.iterator(); while (it.hasnext()) {   user u = it.next();   system.out.println(u.link + " " + u.url); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -