Java knowledge point summary-packing and unpacking

Source: Internet
Author: User

Continue Looking Java. Today is girls' day. No one gives gifts. boys in our class are famous for their frustrations, so they never have hope. I just saw the beautiful women go to the movies, eat, sing, and give gifts. Every girl in the lab sent a bunch of chocolate flowers last year, but this year it seems there is nothing. Even the teacher forgot the girl's day, which is a terrible thing.

Forget it. Have a drink tomorrow. Haha.

But today I went to the dining room to have dinner and received a gift from a cute boy. But he gave it to all the girls who passed ~

Why do I complain about each technical post ~ Is it true that the menopause is approaching ~


Today I reviewed the disassembly box. Today I saw the same example when I checked the TaintDroid to illustrate why the entire class would be infected. What is the fate of the disassembly box ~


The conversion class can convert between the basic type variables and strings. There are two methods to convert the string value to the basic type.
  • Use parseXxx (String s) Static Method
  • Using the Xxx (String s) constructor provided by the packaging class, the String class provides multiple overloaded valueOf () Methods to convert basic types into character types.

    Check the Code:
    String intStr="123";int it1 = Integer.parseInt(intStr);int it2 = new Integer(intStr);String fltStr = "123.45"float ft1 = Float.parse(fltStr);float ft2 = new Float(fltStr)String str = String.valueOf(2.34f);

    See the following code:
    Integer in1 = 1; Integer in2 = 1; // output trueSystem. out. println (in1 = in2); Integer in3 = 128; Integer in4 = 128; // outputs falseSystem. out. println (in3 = in4 );

    Then let's take a look at the Code:
    Integer in1 = 1; Integer in2 = 1; // output trueSystem. out. println (in1 = in2); Integer in3 = 128; Integer in4 = 128; // outputs falseSystem. out. println (in3 = in4 );

    The output of the comparison is different. This is why the first value is the same and the second value is different. View the source code of the Java. lang. Integer class in the Java System.
    public static Integer valueOf(int i){  if (i < -128 || i >127)  {        return new Integer(i);  }  return valueOfCache.CACHE [i+ 128];}static class valueOfCache{ static final Integer[] CACHE = new Integer[256]; static {   for(int i=-128; i<=127; i++){     CACHE[i+128] = new Integer(i);   } }}

    Integers between-128-127 are automatically packed into Integer instances and cached in an array named CACHE. If it is not in this range, create an Integer instance again.
    In the referenced object, different addresses have different values. So it is false.



















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.