「java」StringUtils.join()メソッドで文字列を結合するサンプル
書式
ArrayUtils.toObject(文字列配列)
StringUtils.join(オブジェクト名,",")
使用例
package com.arkgame.study;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
public class StringUtilsDemo {
public static void main(String[] args) {
char[] cftA = { 's', 't', 'u', 'd', 'y' };
char[] cftB = { 'a', 'r', 'k', 'g', 'a', 'm', 'e' };
System.out.println("結果A: " + testFunc(cftA));
System.out.println("結果B: " + testFunc(cftB));
}
//関数testFunc
public static String testFunc(char[] target) {
String result = StringUtils.join(ArrayUtils.toObject(target), ",");
return result;
}
}
実行結果
結果A: s,t,u,d,y
結果B: a,r,k,g,a,m,e