Article From:


********************Packaging Type***************************************

1. Why are there packaging types?

javaIt is an object-oriented language, but because of the existence of eight basic types, Java is not a fully object-oriented language.

In order to make the Java language fully object-oriented, Java designers encapsulate each basic type to design the corresponding basic type

Packing type.



int long float double
byte short

Integer Long Float Double
Byte Short


char Character

int Integer

The rest are capitalized.


********************Basic Type, Packaging Type and String Conversion **************************************

Demonstration code:

package com.chapter5;

* Author: zhangzy
* Company: Blue Bridge Software College
* Time: June 29, 2017, 3:13:01 p.m.
* Function: Demonstrate three transitions of basic type wrapper type strings
public class Demonstrates the three-way conversion of basic type wrapper type strings {

public static void main(String[] args) {

//——————-I. Conversion of Basic Types and Packaging Types——————————————————————————————————————
//1. Basic Type – ——- gt; Packaging Type
//Integer integerI = new Integer(10);
//Integer integer = 10;//jdk5.0New Features Auto-boxing
//Auto-packing: Assigning basic types directly to packaging types automatically converts them into packaging types called auto-packing.
//2.Packaging Type – – – – & gt; Basic Type
//(1) Wrapper type object. xxxValue () intValue () doubleValue ()
/*Integer integerI = new Integer(10);

int i = integerI.intValue();
//(2) Auto-unboxing
/*Integer integerI = new Integer(10);
int i = integerI;//Auto-unboxing*/

//——————-2. Conversion between basic types and strings————————————————————————————————————————
//1. Basic type – –& gt; string
/*String s = String.valueOf(10);
//2. String——–& gt; Basic Type
// Basic type = wrapper class. parseXXX (string) Integer. parseInt (“10”)
/*String s = “10”;

int i = Integer.parseInt(s);


//——————-3. Conversion between packing type and string————————————————————————————————————————–
//1. Packaging Type – – – – & gt; String
/*Integer integerI = new Integer(10);

String s = integerI.toString();
//2. String – —-& gt; Packing Type
/*Integer integer = new Integer(“10”);

********************String Builder and String Buffer********************************************************

1. append()

Addition at the back

2. insert(Subscript, string)

Insert a string at the specified subscript position


Demonstration code:

package com.chapter5;

public class Demonstration string variable {

public static void main(String[] args) {

StringBuilder sb = new StringBuilder(“aaa”);

System.out.println(“sb=” + sb);//sb=aaa

sb.append(“bbb”);//append() String Addition Method

System.out.println(“sb=” + sb);//sb=aaabbb


System.out.println(“sb=” + sb);//aaacccbbb

**************String、StringBuilderDistinction from String Buffer (Interview Question)********************************************


String constants, objects created by String classes, once created in memory, their values are invariable…

StringBuffer and StringBuilder are string variables

Its value can be changed.

StringBufferThe difference between StringBuilder and StringBuilder

1. StringBuffer StringBuffer is a thread-safe version of StringBuilder, which supports multiple threads.

2.StringBuilderIt does not support multi-threading, and it has high running efficiency under single-threading.


Link of this Article: Java packaging type

Leave a Reply

Your email address will not be published. Required fields are marked *