Java Char Array Create toCharArray(CharSequence cs)

Here you can find the source of toCharArray(CharSequence cs)

Description

Green implementation of toCharArray.

License

Open Source License

Parameter

Parameter Description
cs the CharSequence to be processed

Return

the resulting char array

Declaration

static char[] toCharArray(CharSequence cs) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*www .ja  v a  2  s .  c  o m*/
     * Green implementation of toCharArray.
     *
     * @param cs the {@code CharSequence} to be processed
     * @return the resulting char array
     */
    static char[] toCharArray(CharSequence cs) {
        if (cs instanceof String) {
            return ((String) cs).toCharArray();
        } else {
            int sz = cs.length();
            char[] array = new char[cs.length()];
            for (int i = 0; i < sz; i++) {
                array[i] = cs.charAt(i);
            }
            return array;
        }
    }
}

Related

  1. toCharArray(byte[] src)
  2. toCharArray(char... values)
  3. toCharArray(CharSequence chars)
  4. toCharArray(CharSequence charSequence)
  5. toCharArray(CharSequence charSequence)
  6. toCharArray(double[][] array)
  7. toCharArray(final byte[] array)
  8. toCharArray(int number, int exactArrayLength)
  9. toCharArray(String map)