KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > T3105r2


1
2 class T3105r2 {
3     static final String JavaDoc s0001 = "a";
4     static final String JavaDoc s0002 = s0001 + s0001;
5     static final String JavaDoc s0004 = s0002 + s0002;
6     static final String JavaDoc s0008 = s0004 + s0004;
7     static final String JavaDoc s0010 = s0008 + s0008;
8     static final String JavaDoc s0020 = s0010 + s0010;
9     static final String JavaDoc s0040 = s0020 + s0020;
10     static final String JavaDoc s0080 = s0040 + s0040;
11     static final String JavaDoc s0100 = s0080 + s0080;
12     static final String JavaDoc s0200 = s0100 + s0100;
13     static final String JavaDoc s0400 = s0200 + s0200;
14     static final String JavaDoc s0800 = s0400 + s0400;
15     static final String JavaDoc s1000 = s0800 + s0800;
16     static final String JavaDoc s2000 = s1000 + s1000;
17     static final String JavaDoc s4000 = s2000 + s2000;
18     static final String JavaDoc s8000 = s4000 + s4000;
19     static final String JavaDoc sffff = s8000 + s4000 + s2000 + s1000
20                               + s0800 + s0400 + s0200 + s0100
21                               + s0080 + s0040 + s0020 + s0010
22                               + s0008 + s0004 + s0002 + "b"; // still constant!
23

24     static final String JavaDoc toobig = sffff + "c"; // can't be constant
25

26     public static void main(String JavaDoc[] args) {
27         if (toobig.equals(""))
28             System.out.println("String was lost completely");
29         else if (toobig.endsWith("b"))
30             System.out.println("String was truncated at 0xffff bytes");
31         else if (toobig.endsWith("abc")) {
32             String JavaDoc alternate = sffff;
33             alternate += "c";
34             alternate = alternate.intern();
35             if (alternate != toobig)
36                 System.out.println("String was not interned");
37             else
38                 System.out.println("OK");
39         } else
40             System.out.println("Unexpected case");
41     }
42 }
43     
Popular Tags