length是对数组而言的,指的是数组的长度。
length()是对字符串而言的,指的是字符串所包含的字符个数。
public class LengthDemo { public static void main(String args[]) { String str = "Today is Monday"; System.out.println(str.length()); String[] str2 = {"abc","good","alas","ok"}; System.out.println(str2.length); int[] a = new int[5]; System.out.println(a.length); } }
结果:
15
4
5