Storage principle of reference types: Reference types inherit from the Object class (also reference types) and store data according to the memory model of storing objects in Java. This type of data is stored using the Java memory heap and memory stack. Storage, simply put, "references" are stored on the ordered memory stack, while the value of the object itself is stored on the memory heap;

Difference: The difference between basic data types and reference types is mainly that basic data types are allocated on the stack, while reference types are allocated on the heap (requiring the concepts of stack and heap in Java),
What data type does string string belong to in Java?
String in Java is a reference data type. Because String is a class.
Note: String class is immutable, so once you create a String object, its value cannot be changed (see the notes section for details).
The String class has 11 construction methods. These methods provide different parameters to initialize the string, such as providing a character array parameter:
public class StringDemo{
public static void main(String args[]){
char[] helloArray = { 'r', 'u', 'n', 'o', 'o', 'b'};
String helloString = new String(helloArray);
System.out.println( helloString );
}
}
The compilation and running results of the above example are as follows:
runoob
The difference between the two ways of creating a string object
The direct assignment method creates the object in the constant pool in the method area
String str="hello";//直接赋值的方式
The string object created through the construction method is in the heap memory
String str=new String("hello");//实例化的方式The above is the detailed content of What data type is string?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools





