Java Char Array to String charsToString(char[] chars)

Here you can find the source of charsToString(char[] chars)

Description

Converts a binary zero terminated char-array to a string.

License

Apache License

Parameter

Parameter Description
chars a parameter

Declaration

public static String charsToString(char[] chars) 

Method Source Code

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

public class Main {
    /**/*from w  ww. j  ava  2s  .co m*/
     * Converts a binary zero terminated char-array to a string.
     * 
     * @param chars
     * @return
     */
    public static String charsToString(char[] chars) {
        int lastBinZero = chars.length - 1;
        while (lastBinZero >= 0 && chars[lastBinZero] == 0) {
            lastBinZero--;
        }
        return new String(chars, 0, lastBinZero + 1);
    }
}

Related

  1. charArrayToString(char[] ch, String separator)
  2. charArrayToString(char[] input, int offset, int length, int maxChars)
  3. charArrayToString(Character[] chars)
  4. charArrayToXml(char[] input, int offset, int length)
  5. charsToString(char[] chars)