Total Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package com.base; |
||
16 | public static <T> String implode(String glue, List<T> list) { |
||
17 | // list is empty, return empty string |
||
18 | if (list == null || list.isEmpty()) { |
||
19 | return ""; |
||
20 | } |
||
21 | |||
22 | Iterator<T> iter = list.iterator(); |
||
23 | |||
24 | // init the builder with the first element |
||
25 | StringBuilder sb = new StringBuilder(); |
||
26 | sb.append(iter.next()); |
||
27 | |||
28 | // concat each element |
||
29 | while (iter.hasNext()) { |
||
30 | sb.append(glue).append(iter.next()); |
||
31 | } |
||
32 | |||
33 | // return result |
||
34 | return sb.toString(); |
||
35 | } |
||
52 |