Java Char Array Create toCharArray(String s)

Here you can find the source of toCharArray(String s)

Description

Converts the given string into an array of characters.

License

Open Source License

Parameter

Parameter Description
s the string to be converted.

Return

an array of characters representing the given string or an empty array if the given string is null or empty.

Declaration

public static char[] toCharArray(String s) 

Method Source Code

//package com.java2s;
/* /* ww w  .j ava 2s. com*/
 * Copyright(c) 2005 Center for E-Commerce Infrastructure Development, The
 * University of Hong Kong (HKU). All Rights Reserved.
 *
 * This software is licensed under the GNU GENERAL PUBLIC LICENSE Version 2.0 [1]
 * 
 * [1] http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 */

public class Main {
    /**
     * Converts the given string into an array of characters.
     * 
     * @param s the string to be converted.
     * @return an array of characters representing the given string or 
     *          an empty array if the given string is null or empty.
     */
    public static char[] toCharArray(String s) {
        return s == null ? new char[] {} : s.toCharArray();
    }
}

Related

  1. toCharArray(double[][] array)
  2. toCharArray(final byte[] array)
  3. toCharArray(int number, int exactArrayLength)
  4. toCharArray(String map)
  5. toCharArray(String s)
  6. toCharArray(String s)
  7. toCharArray(String str)
  8. toCharArray(String str)
  9. toCharArray(String str)