String类中getBytes()方法的用法

public class class6_4

             {

                      public static void main(String args[])

                      {

                               String s1=new String("astgahg");

                               byte[] b=s1.getBytes();

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


                               String s2=new String(b,0,3);

                               String s3=new String(b,0,4);

                               String s4=new String(b,1,2);

                               System.out.println(s2);

                               System.out.println(s3);

                               System.out.println(s4);

                      }

             }

运行以后的结果为

数组b的长度为:7
ast
astg
sts

你可能感兴趣的:(String类中getBytes()方法的用法)