java中length与length()

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

posted on 2017-07-03 21:27  Deltadeblog  阅读(552)  评论(0编辑  收藏  举报

导航