String pooling is a process in which a single copy of each distinct string value is stored. Otherwise, strings are immutable. This way the strings can contain the same data and share the same memory. In this way, the memory required will be greatly reduced.
When the 'intern' function is called:
It checks for equality between two strings - i.e. whether the string object exists in the string constant pool ( SCP).
If available, the string will be obtained from the pool and returned. Otherwise, a new string object is created and added to the pool. A reference to the string object is also returned.
For two strings 'a' and 'b', if and only if a.equals(b) returns true, a.intern() == b.intern( ) is true.
Let’s look at an example:
Example
Demonstration
public class Demo{ public static void main(String[] args){ String s1 = new String("Its"); String s2 = s1.concat("sample"); String s3 = s2.intern(); System.out.println("Checking equality of object 2 and 3 :"); System.out.println(s2 == s3); String s4 = "Its a sample"; System.out.println("Checking equality of object 3 and 4 :"); System.out.println(s3 == s4); } }
Output
Checking equality of object 2 and 3 : true Checking equality of object 3 and 4 : false
A file named The Demo class contains the main function. Three instances of String objects are defined here, where the second string is the concatenation of the first string with different values. The third string is calling the ' intern ' function on the second string. These strings are compared using the '==' operator and the results are displayed on the console.
The above is the detailed content of In Java, the implementation of string. For more information, please follow other related articles on the PHP Chinese website!

如何使用Java开发一个基于Cassandra的地理位置数据应用地理位置数据应用在现代社会中被广泛使用,例如地图导航、位置共享、位置推荐等。Cassandra是一个分布式、高可扩展性的NoSQL数据库,它能够处理海量数据,特别适合存储和查询地理位置数据。本文将介绍如何使用Java开发一个基于Cassandra的地理位置数据应用,并提供具体的代码示例。1.环境

Java中LinkedList类是一个实现了链表数据结构的类,它提供了许多有用的方法来操作链表。其中,removeFirst()方法可以用来从链表头部删除元素。下面将介绍如何使用LinkedList.removeFirst()方法,并且给出具体的代码示例。在使用LinkedList.removeFirst()方法之前,我们首先需要创建一个LinkedList

Linux环境下安装Kafka的详细步骤1.前提条件操作系统:Linux(推荐使用Ubuntu或CentOS)Java:JDK8或更高版本ZooKeeper:版本3.4或更高版本Kafka:最新稳定版本2.安装Javasudoapt-getupdatesudoapt-getinstalldefault-jdk3.安装ZooKeeperwg

Oracle数据库中常见的数据类型有很多种,包括数值型、字符型、日期型等。下面将具体介绍一些常见的数据类型,并附上相应的代码示例。数值型数据类型:NUMBER:用于存储数值类型数据,可以根据需要指定精度和范围。示例:CREATETABLEtest_table(idNUMBER(10),salaryNUMBER(8,2));INTEGER:用

利用Redis和Java实现分布式计数器:如何实现高并发引言:在现代互联网应用程序开发中,高并发是一个常见的挑战。当多个用户同时访问一个应用程序时,它需要能够正确地处理和跟踪每个用户的请求,以避免数据的丢失或混乱。在这篇文章中,我们将讨论如何利用Redis和Java实现一个分布式计数器,以实现高并发的数据跟踪和管理。一、Redis简介Redis是一个开源的基

如何利用Laravel实现数据同步和异步处理功能引言:Laravel是一款以简洁、优雅的语法和强大功能而闻名的PHP框架。在现代Web开发中,数据同步和异步处理是非常常见的需求。利用Laravel框架,我们可以轻松实现这些功能,并且提高网站的性能和用户体验。本文将介绍如何利用Laravel实现数据同步和异步处理功能,并提供具体的代码示例。一、数据同步功能实现

vue的Upload上传功能怎么实现随着Web应用的发展,文件上传功能已经变得越来越常见。Vue是一种流行的JavaScript框架,提供了便捷的方式来构建现代化的Web应用程序。在Vue中,可以通过使用Vue的Upload组件来实现文件上传功能。本文将介绍如何使用Vue来实现文件上传功能,并提供具体的代码示例。首先,在Vue项目中安装所需的依赖。可以使用n

如何在Java中使用Linux脚本操作实现远程登录概述:远程登录是在网络环境中,使用一台计算机登录到其他计算机上进行操作的一种方式。在Linux系统中,我们通常会使用SSH协议来进行远程登录。本文将介绍如何在Java中通过调用Linux脚本来实现远程登录的操作,并给出具体的代码示例。步骤一:编写Linux脚本代码首先,我们需要编写一个Linux脚本,用于通过


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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