string

26 Sep: String – Best Pratices

Never, never, never use the String constructor Whenever you want to instantiate a String object, never use its constructor but always instantiate it directly. For example: //don’t: String slow = new String(“Yet another string object”); //do String fast = “Yet another string object”; From the Javadoc: Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable. Pattern and regular expressions For performance reasons, instances of pattern (java.util.regex.Pattern) should be…