fork download
  1.  
  2. class Test {
  3. public static void main(String[] args) {
  4. test('h', 'e', 'l', 'l', 'o');
  5. test('m', 'a', 'i', 'n');
  6. }
  7. static void test(char... arg) {
  8. String s1 = new String(arg), s2 = s1.intern();
  9. System.out.println('"'+s1+'"'
  10. +(s1!=s2? " existed": " did not exist")+" in the pool before");
  11. System.out.println("is the same as \"hello\": "+(s2=="hello"));
  12. System.out.println("is the same as \"main\": "+(s2=="main"));
  13. System.out.println();
  14. }
  15. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
"hello" did not exist in the pool before
is the same as "hello": true
is the same as "main": false

"main" existed in the pool before
is the same as "hello": false
is the same as "main": true