提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将int数组转换为字符串
import java.util.Arrays; /** nowjava.com 提供 **/ public class Main { public static void main(String args[]){ int[] intNumbers = new int[]{1, 2, 3, 4, 5}; StringBuffer sbfNumbers = new StringBuffer(); String strSeparator = " "; if(intNumbers.length > 0){ sbfNumbers.append(intNumbers[0]); for(int i=1; i < intNumbers.length; i++){ sbfNumbers.append(strSeparator).append(intNumbers[i]); } } System.out.println("int array converted to String using for loop"); //n o w j a v a . c o m - 时代Java System.out.println(sbfNumbers.toString()); String strNumbers = Arrays.toString(intNumbers); System.out.println("String generated from Arrays.toString method: " + strNumbers); strNumbers = strNumbers.replaceAll(", ", str