Changeset 95


Ignore:
Timestamp:
09/02/08 11:30:53 (10 years ago)
Author:
kuo.chaoyi
Message:

增加String教學範例.

Location:
trunk/Java_1000/KuoSCJP1000/src/kuoscjp1000/string
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Java_1000/KuoSCJP1000/src/kuoscjp1000/string/StringHeap.java

    r86 r95  
    77/** 
    88 * 
    9  * @author chaoyi 
     9 * @author ChaoYi, Kuo 
    1010 */ 
    1111public class StringHeap { 
     
    1717        // TODO code application logic here 
    1818        char c1 = 'A'; 
    19         String s1 = "A"; // (String pool) 
    20         String s2 = new String("A"); // Heap 
     19        String s1 = "A"; // instance in String constant pool 
     20        String s2 = new String("A"); // instance in Heap 
     21        String s4 = new String("A"); // instance in Heap 
    2122 
    2223        // String == char: incompared 
     
    2425        // System.out.println("c1 vs s1 ==" + s1 == c1); // error 
    2526 
    26         System.out.println("s1 vs s2 = " + s1.equals(s2)); 
    27         System.out.println("s1 vs s2 = " + (s1 == s2)); 
     27        System.out.println("s1 equals s2 => " + s1.equals(s2)); 
     28        System.out.println("s1 == s2 => " + (s1 == s2)); 
     29        System.out.println("s2 == s4 => " + (s2 == s4)); 
    2830 
    2931        String s3 = "B"; // JVM auto Constructor "B" (String pool) 
    30         s3 = "b"; // JVM auto Constructor "b" (String pool) 
     32        String s5 = "B"; // String pool 
     33        System.out.println("s3 == s5 => " + (s3 == s5)); 
    3134         
    3235 
Note: See TracChangeset for help on using the changeset viewer.