目录

String intern()

描述 (Description)

此方法返回字符串对象的规范表示。 因此,对于任何两个字符串st ,当且仅当s.equals(t)为真时,s.intern()== t.intern()才为真。

语法 (Syntax)

以下是此方法的语法 -

public String intern()

参数 (Parameters)

这是参数的细节 -

  • 这是一种默认方法,不接受任何参数。

返回值 (Return Value)

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

例子 (Example)

import java.io.*;
public class Test {
   public static void main(String args[]) {
      String Str1 = new String("Welcome to iowiki.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());
   }
}

这将产生以下结果 -

输出 (Output)

Canonical representation: Welcome to iowiki.com
Canonical representation: WELCOME TO SUTORIALSPOINT.COM
↑回到顶部↑
WIKI教程 @2018