Java Array to Delimited String arrayToCommaString(int[] array)

Here you can find the source of arrayToCommaString(int[] array)

Description

array To Comma String

License

Open Source License

Declaration

public static String arrayToCommaString(int[] array) 

Method Source Code

//package com.java2s;
/* ArrayUtil.java 1.0 2010-2-2
 * /*from  www .j a  va 2 s.  com*/
 * Copyright (c) 2010 by Chen Zhiwu
 * All rights reserved.
 * 
 * The copyright of this software is own by the authors.
 * You may not use, copy or modify this software, except
 * in accordance with the license agreement you entered into 
 * with the copyright holders. For details see accompanying license
 * terms.
 */

public class Main {
    public static String arrayToCommaString(int[] array) {
        StringBuffer sb = new StringBuffer();
        for (int i = array.length - 1; i >= 0; i--) {
            if (array[i] == 0) {
                continue;
            }
            sb.append(array[i]);
            sb.append(i == 0 ? "" : ",");
        }
        return sb.toString();
    }

    public static String toString(Object[] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i]);
            sb.append(i < array.length - 1 ? "," : "");
        }
        return sb.toString();
    }
}

Related

  1. arrayToCommaDelimitedString(Object[] arr)
  2. arrayToCommaDelimitedString(Object[] arr)
  3. arrayToCommaDelimitedString(Object[] strings)
  4. arrayToCommaSeparatedString(int[] array)
  5. arrayToCommaString(int[] array)
  6. arrayToDelimitedString(Object[] arr, String delim)
  7. arrayToDelimitedString(Object[] arr, String delim)
  8. arrayToDelimitedString(Object[] arr, String delim)
  9. arrayToDelimitedString(String[] values, String delimiter)