Java 中的 String intern()函数

首页 / Java入门教程 / Java 中的 String intern()函数

对于任何两个字符串 s 和 t ,当且仅当s.equals(t)为s时,s.intern()== t.intern()才为true。

String intern() - 语法

这是此方法的语法-

public String intern()

String intern() - 返回值

  • 此方法返回字符串对象的规范表示形式。

String intern() - 示例

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str1=new String("Welcome to Learnfk.com");
      String Str2=new String("WELCOME TO SUTORIALSPOINT.COM");

      System.out.print("Canonical representation:" );
      System.out.println(Str1.intern());

      System.out.print("Canonical representation:" );
      System.out.println(Str2.intern());
   }
}

这将产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/java/java-string-intern.html

来源:LearnFk无涯教程网

Canonical representation: Welcome to Learnfk.com
Canonical representation: WELCOME TO SUTORIALSPOINT.COM

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

透视HTTP协议 -〔罗剑锋(Chrono)〕

说透数字化转型 -〔付晓岩〕

React Hooks 核心原理与实战 -〔王沛〕

零基础入门Spark -〔吴磊〕

全链路压测实战30讲 -〔高楼〕

Web 3.0入局攻略 -〔郭大治〕

现代React Web开发实战 -〔宋一玮〕

Vue 3 企业级项目实战课 -〔杨文坚〕

云原生架构与GitOps实战 -〔王炜〕

好记忆不如烂笔头。留下您的足迹吧 :)