Java String length

Introduction

The length() method from String class, shown here:

int length() 

The following fragment prints "3", since there are three characters in the string s:

char chars[] = { 'a', 'b', 'c' };  
String s = new String(chars);  
System.out.println(s.length()); 
public class Main {
   public static void main(String[] args) {
      String message = "Welcome to demo2s.com";
      System.out.println("The length of " + message + " is " + message.length());

   }/*from w  ww  .  j av a2  s  .com*/
}



PreviousNext

Related