Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using iterator question  RSS feed

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use the iterator when pulling back a resultset from a sql query and then looping through that resultset in order to concatenate each record to one String value.

I don't know if I'm on the right track because I can't make sense of how to concatenate each record to that single String value.

Any help or direction would be appreciated. Here is the code I am using:

<code>
public String findItemDesc(String reqNum, String entity) {
List itemDescList = _findItemDesc.execute(new Object[] {reqNum, entity});
Iterator items = itemDescList.iterator();
while (items.hasNext()) {
String itemList = (String)itemDescList.add(itemDescList);
}
return itemList;
}
</code>

Thanks.
[ April 13, 2006: Message edited by: Melinda Savoy ]
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you pls code back to the forum.....

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but I'm not understanding your comment.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Here is the typical loop for processing items in a list:

Where theList is a list of X's.
In Java versions 1.5 or later, you may use the enhanced for loop:


2. To contatenate Strings into a single String object s, either write:

...or use a StringBuffer or StringBuilder, because excessive String concatentation can be inefficient:
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff,

Thanks for the reply, I think. I'm sure however that displaying an emoticon for what your "feeling" is irrelevant to my question. This is a BEGINNER list is that not correct?

Regards.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Melinda Savoy:
Thanks for the reply, I think. I'm sure however that displaying an emoticon for what your "feeling" is irrelevant to my question. This is a BEGINNER list is that not correct?


That line about emoticons (once spoken by my lookalike namesake) wasn't aimed at your post -- it's my signature file and is appended to all my posts. No slight intended.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!