Transferred from: http://blog.csdn.net/sk880609/article/details/7524006
1, the length property in Java is said for the array, for example, you declare an array, you want to know the length of this array is used to this property.
2. The length () method in Java is for string strings, and if you want to see the length of the string, use Length ().
3. The size () method in Java is said for a generic collection, and if you want to see how many elements of the generic, call this method to view it!
Examples are as follows:
Importjava.util.ArrayList;Importjava.util.Collection; Public classTest { Public Static voidMain (string[] args) {int[] array = {0, 1, 2, 3, 4, 5, 6, 7}; String Str= "Hello world!"; Collection<String> C =NewArraylist<string>(); C.add ("Hello"); C.add ("World"); C.add ("Java"); System.out.println ("Length:" +array.length); System.out.println ("Length ():" +str.length ()); System.out.println ("Size ():" +c.size ()); }}
Output Result:
Length:8Length ():size ():3
Length,length (), size () difference in Java