JAVAString相关API测试------JAVA

我就是我 2024-03-22 03:34 173阅读 0赞
  1. public class StringTest
  2. {
  3. public static void main(String[] args)
  4. {
  5. // test();
  6. // test2();
  7. // test3();
  8. // test4();
  9. test5();
  10. }
  11. public static void test()
  12. {
  13. String s1 = "Hello";
  14. String s2 = "Hello";
  15. System.out.println(s1 == s2);
  16. s2 = "hi";
  17. System.out.println(s1);
  18. }
  19. public static void test2()
  20. {
  21. String s1 = "Hello";
  22. String s2 = "Hello";
  23. s2 += "world";
  24. System.out.println(s1);
  25. }
  26. public static void test3()
  27. {
  28. String s1 = "Hello";
  29. String s2 = "World";
  30. String s3 = "HelloWorld";
  31. String s4 = "Hello" + "World";
  32. String s5 = s1 + "World";
  33. String s6 = "Hello" + s2;
  34. String s7 = s1 + s2;
  35. System.out.println(s3 == s4);
  36. System.out.println(s3 == s5);
  37. System.out.println(s3 == s6);
  38. System.out.println(s3 == s7);
  39. System.out.println(s5 == s6);
  40. System.out.println(s5 == s7);
  41. System.out.println();
  42. String s8 = s5.intern();
  43. System.out.println(s3 == s8);
  44. }
  45. public static void test4()
  46. {
  47. final String s1 = "Hello";
  48. final String s2 = "World";
  49. String s3 = "HelloWorld";
  50. String s4 = "Hello" + "World";
  51. String s5 = s1 + "World";
  52. String s6 = "Hello" + s2;
  53. String s7 = s1 + s2;
  54. System.out.println(s3 == s5);
  55. System.out.println(s3 == s6);
  56. System.out.println(s3 == s7);
  57. }
  58. public static void test5()
  59. {
  60. String s1 = "Hello";
  61. String s2 = "World";
  62. String s3 = "HelloWorld";
  63. String s4 = s1.concat(s2);
  64. String s5 = "Hello".concat("World");
  65. System.out.println(s3 == s4);
  66. System.out.println(s3 == s5);
  67. }
  68. }

public class StringTest
{
public static void main(String[] args)
{
// test();
// test2();
// test3();
// test4();
test5();
}
public static void test()
{
String s1 = “Hello”;
String s2 = “Hello”;
System.out.println(s1 == s2);
s2 = “hi”;
System.out.println(s1);
}

public static void test2()
{
String s1 = “Hello”;
String s2 = “Hello”;
s2 += “world”;
System.out.println(s1);
}

public static void test3()
{
String s1 = “Hello”;
String s2 = “World”;
String s3 = “HelloWorld”;
String s4 = “Hello” + “World”;
String s5 = s1 + “World”;
String s6 = “Hello” + s2;
String s7 = s1 + s2;
System.out.println(s3 == s4);
System.out.println(s3 == s5);
System.out.println(s3 == s6);
System.out.println(s3 == s7);
System.out.println(s5 == s6);
System.out.println(s5 == s7);
System.out.println();
String s8 = s5.intern();
System.out.println(s3 == s8);
}
public static void test4()
{
final String s1 = “Hello”;
final String s2 = “World”;
String s3 = “HelloWorld”;
String s4 = “Hello” + “World”;
String s5 = s1 + “World”;
String s6 = “Hello” + s2;
String s7 = s1 + s2;
System.out.println(s3 == s5);
System.out.println(s3 == s6);
System.out.println(s3 == s7);
}

public static void test5()
{
String s1 = “Hello”;
String s2 = “World”;
String s3 = “HelloWorld”;
String s4 = s1.concat(s2);
String s5 = “Hello”.concat(“World”);
System.out.println(s3 == s4);
System.out.println(s3 == s5);
}
}

发表评论

表情:
评论列表 (有 0 条评论,173人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Spring相关API

    > ⭐作者介绍:大二本科网络工程专业在读,持续学习Java,努力输出优质文章 > ⭐作者主页:[@逐梦苍穹][Link 1] > ⭐所属专栏:[JavaEE][]、[S

    相关 JavaString

    /\ 接口 接口中只有常量和抽象方法 常量 默认 类型public static final 接口中定义时,写不写都是这样 方法的默认类