permaculture playing cards
The moose likes Beginning Java and the fly likes what is wrong with this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is wrong with this?" Watch "what is wrong with this?" New topic

what is wrong with this?

rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
Is this wrong or is there a better way to write it?
for (int i=0;i<userList.size();i++);
} //new stuff

p.s. userArea=textArea, userList=LinkedList<String> , newline=char value'/n'
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

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:


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


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.

[Jess in Action][AskingGoodQuestions]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.

There is no emoticon for what I am feeling!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

Ah. Two errors!
I agree. Here's the link:
subject: what is wrong with this?
It's not a secret anymore!