(1)String类型转char[] 类型,使用String类型的toCharArray()方法;
(2)char[] 类型转String类型,使用String.valueOf()方法;
public class Test { public static void main(String[] args) { // String转char[] String str = "Hello World!"; char[] cs = str.toCharArray(); for (char c : cs) System.out.print(c); System.out.println(); // char[] 类型转String类型 char[] cs2 = { ‘I‘, ‘L‘, ‘o‘, ‘v‘, ‘e‘, ‘C‘, ‘o‘, ‘d‘, ‘e‘ }; String str2 = String.valueOf(cs2); System.out.println(str2); } }
Hello World! ILoveCode
原文地址:https://www.cnblogs.com/yongh/p/9689798.html
时间: 2024-11-05 22:07:14