Java Array Convert to arrayToSVMLightString(int[] array)

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

Description

array To SVM Light String

License

Apache License

Declaration

public static String arrayToSVMLightString(int[] array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String arrayToSVMLightString(int[] array) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                str.append(i).append(":").append(array[i]).append(" ");
            }/*from w  w w .j  av a2 s .c  o  m*/
        }
        return str.toString();
    }

    public static String arrayToSVMLightString(float[] array) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                str.append(i).append(":").append(array[i]).append(" ");
            }
        }
        return str.toString();
    }

    public static String arrayToSVMLightString(double[] array) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                str.append(i).append(":").append(array[i]).append(" ");
            }
        }
        return str.toString();
    }
}

Related

  1. arrayToOneLineSpaceDelimitedString(Object obj[])
  2. arrayToQueryString(String key, Object[] arr)
  3. arrayToSeparatedString(final String[] strings, final String separator)
  4. arrayToSqlInList(String... values)
  5. arrayToSv(String as[], String s)
  6. arrayToUpper(String[] values)
  7. arrayWithoutFirstsElement(final String[] array, final int elementsToRemove)
  8. convertArray(byte[] a)
  9. convertArray(Object columns[], int minLength)