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

33
LINES

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

JavaX fragment (include)

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

public static S join(S glue, S... strings) {
  ret join(glue, Arrays.asList(strings));
}

static S join(Iterable<S> strings) {
  ret join("", strings);
}

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

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

ifclass Pair
static S join(S glue, Pair p) {
  ret p == null ? "" : str(p.a) + glue + str(p.b);
}
endif

Author comment

Began life as a copy of #2000507

download  show line numbers  debug dex   

Travelled to 4 computer(s): cfunsshuasjs, ddnzoavkxhuk, onxytkatvevr, tvejysmllsmz

No comments. add comment

Snippet ID: #1000810
Snippet name: join function + array version
Eternal ID of this version: #1000810/8
Text MD5: 86f8b1d978712e809ce079a0e7fe3d4f
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-20 00:43:04
Source code size: 721 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 214 / 9258
Version history: 7 change(s)
Referenced in: [show]