< Day Day Up > |
10. StringsThis section concern character strings. 10.1. Arrays do not override Object.toStringPrescription: For char arrays, use String.valueOf to obtain the string representing the designated sequence of characters. For other types of arrays, use Arrays.toString or, prior to release 5.0, Arrays.asList. References: Puzzle 12; [JLS 10.7]. 10.2. String.replaceAll takes a regular expression as its first argumentPrescription: Ensure that the argument is a legal regular expression, or use String.replace instead. References: Puzzle 20. 10.3. String.replaceAll takes a replacement string as its second argumentPrescription: Ensure that the argument is a legal replacement string, or use String.replace instead. References: Puzzle 20. 10.4. Repeated string concatenation can cause poor performancePrescription: Avoid using the string concatenation operator in loops. References: [EJ item 33]. 10.5. Conversion of bytes to characters requires a charsetPrescription: Always select a charset when converting a byte array to a string or char array; if you don't, the platform default charset will be used, leading to unpredictable behavior. References: Puzzle 18. 10.6. Values of type char are silently converted to int, not StringPrescription: To convert a char to a string, use String.valueOf(char). References: Puzzles 11 and 23; [JLS 5.1.2]. |
< Day Day Up > |
No comments:
Post a Comment