Skip to content

Commit cdd7a7b

Browse files
committed
Add makeStringList method to ArrayUtils for converting list to string
1 parent d40de80 commit cdd7a7b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

SimpleAPI/src/main/java/com/bencodez/simpleapi/array/ArrayUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,25 @@ public static String makeStringList(ArrayList<String> list) {
324324
}
325325
return string;
326326
}
327+
328+
public static String makeStringList(List<String> list) {
329+
if (list == null) {
330+
return "";
331+
}
332+
String string = new String();
333+
if (list.size() > 1) {
334+
for (int i = 0; i < list.size(); i++) {
335+
if (i == 0) {
336+
string += list.get(i);
337+
} else {
338+
string += ", " + list.get(i);
339+
}
340+
}
341+
} else if (list.size() == 1) {
342+
string = list.get(0);
343+
}
344+
return string;
345+
}
327346

328347
public static String pickRandom(ArrayList<String> list) {
329348
if (list != null) {

0 commit comments

Comments
 (0)