提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将字符串转换为char数组
/* 时代Java公众号 - nowjava.com */ //package com.nowjava; public class Main { public static void main(String[] argv) { String str = "nowjava.com"; System.out.println(java.util.Arrays.toString(strToChars(str))); } private static final char[] EMPTY_CHAR_ARRAY = new char[0]; /** * Convert a String to a char array * @param str The string to convert * @return character array containing the characters in str. An * empty array is returned if str is null. */ public static char[] strToChars(String str) { int len; char[] ret;/*时 代 J a v a - N o w J a v a . c o m 提 供*/ if (str == null)