Length,length (), size () difference in Java
Length property: Used to get the array length.
eg
intAr[] =New int{A}/*** The Length property of the array is obtained*/intLenar = Ar.length;//here lenar=3System.out.println ("ARR Length:" +lenar); Length () Method: Used to get the string length. String Str= "Hello World Java";/*** String Length () method is used to obtain lengths*/intLenstr = Str.length ();//here lenstr=16System.out.println ("Str Length ():" +lenstr); Size () method: Used to get how many elements of a generic collection. Eg:/*** Collection is the largest parent interface for single-value saving in the entire class set, so it needs to be instantiated with a specific subclass*/Collection<String> col =NewArraylist<string>(); Col.add ("Hello"); Col.add ("World"); Col.add ("Java");/*** The class set framework uses the size () method to take the number of elements*/intSizecol = Col.size ();//here sizecol=3System.out.println ("Col size:" +sizecol);
Java Trivia--length,length (), size () method details