Skip to content

Latest commit

 

History

History
60 lines (49 loc) · 2.93 KB

StringUtils.md

File metadata and controls

60 lines (49 loc) · 2.93 KB

StringUtils

Contents

Joining Collections

Sometimes you have a list that needs to become a string. For example

List<Integer> number = Arrays.asList(1, 2, 3, 4, 5);
String text = StringUtils.join(number, ", ");

snippet source | anchor

will produce

1, 2, 3, 4, 5

snippet source | anchor

by invoking the .toString() on each object in the collection.

Joining Collections with a function

if .toString() isn't enough, you can pass in a lambda to do the extra transformation as well. For example:

List<Integer> number = Arrays.asList(1, 2, 3, 4, 5);
String text = StringUtils.join(number, ", ", n -> StringUtils.padNumber(n, 3));

snippet source | anchor

will Produce

001, 002, 003, 004, 005

snippet source | anchor


Back to User Guide