Java Trivia--length,length (), size () method details

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.