Java intern() 方法

Java 教程 · 2019-02-08 22:27:58

intern() 方法返回字符串对象的规范化表示形式。

它遵循以下规则:对于任意两个字符串 s 和 t,当且仅当 s.equals(t) 为 true 时,s.intern() == t.intern() 才为 true。

语法

public String intern()

参数

返回值

一个字符串,内容与此字符串相同,但一定取自具有唯一字符串的池。

实例

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("www.codercto.com");
        String Str2 = new String("WWW.CODERCTO.COM");

        System.out.print("规范表示:" );
        System.out.println(Str1.intern());

        System.out.print("规范表示:" );
        System.out.println(Str2.intern());
    }
}

以上程序执行结果为:

规范表示:www.codercto.com
规范表示:WWW.CODERCTO.COM

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Fluent Python

Fluent Python

Luciano Ramalho / O'Reilly Media / 2015-8-20 / USD 39.99

Learn how to write idiomatic, effective Python code by leveraging its best features. Python's simplicity quickly lets you become productive with it, but this often means you aren’t using everything th......一起来看看 《Fluent Python》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换