JAVAString相关API测试------JAVA
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);
}
}
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);
}
}
还没有评论,来说两句吧...