Java&android Knowledge points Summary (not regularly updated)

Source: Internet
Author: User

1. In Java, the parameter type of some methods is charsequence, when the parameter that is brought in is actually a string, what is going on?????

A: Charsequence is a string implementation of an interface, rather simple, is the requirement is a string of characters. Therefore, each parameter type is a charsequence method and can actually be used to substitute a string object.
Why don't these methods simply define string as the parameter type? Because there are other classes of charsequence types, such as StringBuffer and StringBuilder, these are important classes. The string object is immutable, and the two are mutable, so we often use StringBuffer and StringBuilder in the process of constructing strings. If those methods define string as parameter types, then it is not possible to use those methods on them, first to convert to string. But StringBuffer and StringBuilder convert to string and then convert it over time, using them instead of just using string "addition" to construct a new string is meant to save time, so if a string is used as the parameter type it is a cup.

2.

Java&android Knowledge points Summary (not regularly updated)

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.