Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
what is wrong with this?
rob armstrong
Ranch Hand
Posts: 77
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 24207
46
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
for (String s: userList) { userArea.append(s); userArea.append(newline); }
which is what I would do.
[Jess in Action]
[AskingGoodQuestions]
Jeff Albertson
Ranch Hand
Posts: 1780
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 24207
46
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ah.
Two
errors!
[Jess in Action]
[AskingGoodQuestions]
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Passing data between beans
No getter method for property name of bean userList
Display struts output to jsp
c:forEach and runtime "end" expression
submitting data to database
More...