Welcome on madbean · Feb 18, 2003
Code idiom: inserting a separator between the elements in a list
0Sign in to vote or save
This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.
I use the following code idiom all the time. I know it seems simple, and I know there are other ways of doing it, but when I first saw it a penny dropped. Writer out = ...; List l = ...; String sep = ''; for (Iterator i = l.iterator(); i.hasNext(); ) { String s = (String) i.next(); out.write(sep); out.write(s); sep = ','; } You can see how this works:
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.