java中Student s1=new Student(); s2=s1; s3=s2; s4=s3;创建了几个对象?

2024-11-24 00:59:58
推荐回答(1个)
回答1:

  public class Test {
  public static void main(String[] args) {
  String s1="Welcome to java";
  String s2=s1;
  String s3=new String("Welcome to java");
  String s4=s3.intern();
  
  System.out.println("s1=s2:" + (s1==s2));
  System.out.println("s2=s3:" + (s2==s3));
  System.out.println("s1.equals(s2):" + s1.equals(s2));
  System.out.println("s2.equals(s3):" + s2.equals(s3));
  System.out.println("s1.compareTo(s2):" + s1.compareTo(s2));
  System.out.println("s2.compareTo(s3) :" + s2.compareTo(s3));
  System.out.println("s1==s4:" + (s1==s4));
  System.out.println("s1.charAt(0) :" + s1.charAt(0) );
  System.out.println("s1.indexOf('j') :" + s1.indexOf('j') );
  System.out.println("s1.indexOf('to'):" + s1.indexOf("to"));
  System.out.println("s1.lastindexOf('j') :" + s1.lastIndexOf("j"));
  System.out.println("s1.lastindexOf(\"o\",15):" + s1.lastIndexOf("o",15));
  System.out.println("s1.length():" + s1.length());
  System.out.println("s1.subString(5):" + s1.substring(5));
  System.out.println("s1.SubString(5,11):" + s1.substring(5,11));
  System.out.println("s1.startsWith(\"wel\"):" + s1.startsWith("wel"));
  System.out.println("s1.endsWith(\"java\"):" + s1.endsWith("java"));
  System.out.println("s1.toLowerCase():" + s1.toLowerCase());
  System.out.println("s1.toUpperCase():" + s1.toUpperCase());
  System.out.println("\" Welcome \".trim():" + " Welcome ".trim());
  System.out.println("s1.replace('o','T'):" + s1.replace('o','T'));
  System.out.println("s1.replaceAll(\"o\",\"T\"):" + s1.replaceAll("o","T"));
  System.out.println("s1.replaceFirst(\"o\",\"T\"):" + s1.replaceFirst("o","T"));
  System.out.println("s1.toCharArray():" + s1.toCharArray());
  }
  }