• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is wrong with this?

 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this wrong or is there a better way to write it?
for (int i=0;i<userList.size();i++);
{
userArea.append(userList[i]+newline);
} //new stuff

p.s. userArea=textArea, userList=LinkedList<String> , newline=char value'/n'
thanks
roba
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's one error: userList isn't an array, so you can't use the [] operator with it; you have to call the get() method:

userArea.append(userList.get(i)+newline);

If this is a long list, it's worth breaking the append call into two, to save the extra data-copying that comes from the String addition. So more like

userArea.append(userList.get(i));
userArea.append(newline);

Finally, the "new for loop" is handsomer than this old style; since you're using Tiger you can just write something like



which is what I would do.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E F-H is going to kick himself for missing this but the semi-colon at the end of this line:

for (int i=0;i<userList.size();i++); //<-- dat there

is the body of the loop (an empty statement). The code that follows is not the body of the loop, but instead code following the loop.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah. Two errors!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic