我正在尝试int[]使用Google Guava的Joiner类加入(int数组).
例:
int[] array = { 1, 2, 3 };
String s = Joiner.on(", ").join(array); // not allowed
我检查了StackOverflow和Google.基础课程中没有"一线"转换int[]为Integer[]或List<Integer>.它总是需要一个for循环,或者你自己的手动辅助函数.
有什么建议?
Jen*_*ann 31
Ints是一个包含辅助函数的Guava库.
鉴于int[] array = { 1, 2, 3 }您可以使用以下内容:
String s = Joiner.on(", ").join(Ints.asList(array));
Run Code Online (Sandbox Code Playgroud)
或者更简洁:
String s = Ints.join(", ", array);
Run Code Online (Sandbox Code Playgroud)