Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > TinyBrain | #1000810 - join function + array version

JavaX fragment (include)

public static String join(String glue, Iterable<String> strings) {
  if (strings == null) ret "";
  StringBuilder buf = new StringBuilder();
  Iterator<String> i = strings.iterator();
  if (i.hasNext()) {
    buf.append(i.next());
    while (i.hasNext())
      buf.append(glue).append(i.next());
  }
  return buf.toString();
}

public static String join(String glue, String[] strings) {
  return join(glue, Arrays.asList(strings));
}

static String join(Iterable<String> strings) {
  return join("", strings);
}

static String join(Iterable<String> strings, S glue) {
  return join(glue, strings);
}

public static String join(String[] strings) {
  return join("", strings);
}

Author comment

Began life as a copy of #2000507

download  show line numbers  debug dex   

Travelled to 3 computer(s): cfunsshuasjs, ddnzoavkxhuk, onxytkatvevr

No comments. add comment

Snippet ID: #1000810
Snippet name: join function + array version
Eternal ID of this version: #1000810/4
Text MD5: e1b7b7f4cf101dfd79f3f29c20666c68
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-07 21:44:59
Source code size: 704 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 166 / 9048
Version history: 3 change(s)
Referenced in: [show]