java-String类中to Char Array()方法的用法

public class class6_3

         {

                 public static void main(String args[])

                 {

                         String s1=new String("我是中国人"); //直接赋值

                         char[] c=s1.toCharArray();          
                                 //返回一个字符数组,该字符数组中存放了当前字符串中的所有字符

                         System.out.println("数组c的长度为:"+c.length);

                         System.out.println(c);

                         System.out.println(new String(c));  

                         String s2=new String(c,1,2);    //输出了 是中

                         System.out.println(s2);
                 }

         }

  

运行结果:

  

数组c的长度为:5

我是中国人

我是中国人

是中

posted @ 2021-03-03 16:34  GGood_Name  阅读(496)  评论(0)    收藏  举报