- public class StringBuilderTest {
- public static void main(String[] args){
- int[] arr = {3, 1, 5, 4, 6};
- String s = arrayToString(arr);
- System.out.println(s);
- }
- public static String arrayToString(int[] arr){
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- for(int i = 0; i < arr.length; i++){
- if(i != arr.length-1)
- sb.append(arr[i]).append(",");
- else
- sb.append(arr[i]).append("]");
- }
- return sb.toString();
- }
- }
复制代码
|
|