集册 Java实例教程 知道字符串的长度

知道字符串的长度

欢马劈雪     最近更新时间:2020-01-02 10:19:05

447
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
知道字符串的长度

public class Main {

  public static void main (String[] args) {

    // Create two string objects 
    /** 
    来 自 
    n o w j a   v  a . c o m - 时  代  Java
    **/

    String str1 = new String() ;

    String str2 = new String("Hello") ;


    // Get the length of str1 and str2 

    int len1 = str1.length();

    int len2 = str2.length();


    // Display the length of str1 and str2 

    System.out.println("Length of \"" + str1 + "\" = " + len1);
    /*
    来 自*
   
展开阅读全文