I\'m a C++ guy learning Java. I\'m reading Effective Java and something confused me. It says never to write code like this:
String s = new String(\"silly\");
Java strings are interesting. It looks like the responses have covered some of the interesting points. Here are my two cents.
strings are immutable (you can never change them)
String x = "x";
x = "Y";
string comparisons are contingent on what you are comparing
String a1 = new String("A");
String a2 = new String("A");
a1
does not equal a2
a1
and a2
are object referencesI think you're on the wrong path with trying to use the caseinsensitive class. Leave the strings alone. What you really care about is how you display or compare the values. Use another class to format the string or to make comparisons.
i.e.
TextUtility.compare(string 1, string 2)
TextUtility.compareIgnoreCase(string 1, string 2)
TextUtility.camelHump(string 1)
Since you are making up the class, you can make the compares do what you want - compare the text values.