如何获取字符串长度?
package demo4; public class Demo7 { public static void main(String[] args) { // TODO Auto-generated method stub String password = "1234567890"; int size =password.length(); String password1 = "123 45"; int size1 =password1.length(); System.out.println(size); System.out.println(size1); //注意:字符串用length() 数组用length //length()方法返回的字符串长度包括字符串中的空格。 //String str ="123 45"; 123和45之间有一个空格 //int size = str.length(); size的值为6而不是5 //null 字符串不能使用length(),不然会报错 } }