Skip to main content
Rewording. Remove warning about missing type parameter for the Iterator.
Source Link

Yes, kinda

String.format and as. As for join I think, you need to write your own:

 static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); IteratorIterator<?> iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (!iter.hasNext()) { break; } builder.append(delimiter); } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (!iter.hasNext()) { break; } builder.append(delimiter); } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

String.format. As for join, you need to write your own:

 static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator<?> iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (!iter.hasNext()) { break; } builder.append(delimiter); } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

slight efficienty thanks to 13ren
Source Link
Allain Lalonde
  • 94k
  • 72
  • 190
  • 239

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(Collection<?> s, String delimiter) {   StringBuilder builder = new StringBuilder();   Iterator iter = s.iterator();   while (iter.hasNext()) { builder.append(iter.next());   if (!iter.hasNext()) { break; builder.append(delimiter);  }    }   builder.append(delimiter); }  return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(Collection<?> s, String delimiter) {   StringBuilder builder = new StringBuilder();   Iterator iter = s.iterator();   while (iter.hasNext()) { builder.append(iter.next());   if (iter.hasNext()) { builder.append(delimiter);  } } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (!iter.hasNext()) { break;     }   builder.append(delimiter); }  return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

added 9 characters in body
Source Link
Allain Lalonde
  • 94k
  • 72
  • 190
  • 239

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(CollectionCollection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (iter.hasNext()) { builder.append(delimiter); } } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(Collection s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (iter.hasNext()) { builder.append(delimiter); } } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

Yes, kinda

String.format and as for join I think you need to write your own:

 static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (iter.hasNext()) { builder.append(delimiter); } } return builder.toString(); } 

The above comes from http://snippets.dzone.com/posts/show/91

Changed it to StringBuilder form StringBuffer (see comments)
Source Link
Allain Lalonde
  • 94k
  • 72
  • 190
  • 239
Loading
Source Link
Allain Lalonde
  • 94k
  • 72
  • 190
  • 239
Loading