Java Sundry Tips

Source: Internet
Author: User

1. About arrays
Remember that the BinarySearch method returns the meaning of the numeric value of type int.
If The array contains multiple elements with the specified value, there is no guarantee which one would be found.
and returns 1 when the lookup number is less than any number in the array, and returns when the number of lookups is greater than any number in the array-(ARRAY.LENGTH+1)

SYSTEM.OUT.PRINTLN (Arrays * *)
If the parameter type is char[], then the output is a string of array elements, or a random string if it is an array of other types.

2.static Method Invocation

The following is very simple, but many experienced Java developers will be in the middle. Gossip less say, look at the code:

Nulltest mynulltest = null; System.out.println (Mynulltest.getint ());

When you see this code, many people will think that there will be nullpointerexception. Is it true? Look at the rest of the code again:

Class Nulltest {public     static int getInt () {         return 1;}     }

Always remember that the use of class variables and class methods depends only on the type of reference. Even if the reference is null, it can still be called. From a good practice point of view, it is wise to use Nulltest.getint () instead of Mynulltest.getint (), but the ghost knows when to run into this code.

Java Sundry Tips

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.