· Avoidduplicateliterals: code containing duplicate string literals can be usually be improved by declaring the string as a constant field.
Avoid repeated literal values: Code contains repeated strings and can often be reconstructed to declare this string as a constant.
· Stringinstantiation: Avoid instantiating string objects; this is usually unnecessary.
Initialization of translation strings: Avoid initializing string objects; this is unnecessary.
· Stringtostring: Avoid calling tostring () on string objects; this is unnecessary.
Translation string. tostring (): Avoid calling the tostring () method on string objects. This is unnecessary.
· Inefficientstringbuffering: Avoid concatenating non literals in a stringbuffer constructor or append ().
Inefficient stringbuffering: avoid connecting non-literal data types in the stringbuffer constrtor or append () method
· Unnecessarycasechange: Using specified signorecase () is faster than using touppercase/tolowercase (). Equals ()
Unnecessary case-sensitive Translation: Using signorecase () is faster than converting strings into the same case.
· Usestringbufferlength: Use stringbuffer. Length () to determine stringbuffer length rather than using stringbuffer. tostring (). Equals ("") or stringbuffer. tostring (). Length () =.
Use the length () method of stringbuffer for translation: Use the length () method of the stringbuffer object to calculate the length of the stringbuffer object, instead of using stringbuffer. tostring (). equals ("") or stringbuffer. tostring (). length () =. and other methods
· Appendcharacterwithchar: Avoid concatenating characters as strings in stringbuffer. append.
Use char-type connection characters for translation: Avoid using string-type connection characters when using the append () method of stringbuffer.
· Consecutiveliteralappends: consecutively calling stringbuffer. append with string literals
Translation of continuous literal connections: Call the append () method of stringbuffer continuously when connecting strings
· Useindexofchar: Use string. indexof (char) when checking for the index of a single character; it executes faster.
Translation uses indexof (character): When you detect the position of a single character, use string. indexof (character), which is executed very quickly. Do not use indexof (string)
· Inefficientemptystringcheck: string. trim (). length () is an inefficient way to check if a string is really empty, as it creates a new String object just to check its size. consider creating a static function that loops through a string, checking character. iswhitespace () on each character and returning false if a non-whitespace character is found.
Inefficient empty string translation check: it is inefficient to use string. Trim (). Length () to determine whether the string is null, because it creates a new String object and then determines the size. Consider creating a static method loop string. Use iswhitespace () to check whether each character returns false if it encounters a non-blank character.
· Insufficientstringbufferdeclaration: Failing to pre-size a stringbuffer properly cocould cause it to re-size limit times during runtime. this rule checks the characters that are actually passed into stringbuffer. append (), but represents a best guess "Worst Case" scenario. an empty stringbuffer constructor initializes the object to 16 characters. this default is assumed if the length of the constructor can not be determined.
Inadequate translation of stringbuffer statement: if the appropriate size of stringbuffer cannot be declared beforehand, the size may be continuously re-allocated during the runtime. This rule checks whether the characters are actually passed to stringbuffer. append (), but indicates the best prediction in the worst case. The stringbuffer constrtor with null parameters initializes the object to a capacity of 16 characters by default. This is assumed by default when the construction length cannot be determined.
· Uselessstringvalueof: No need to call String. valueof to append to a string; just use the valueof () argument directly.
Useless valueof method Translation: when calling the append () method, you do not need to use valueof () to convert the parameter once. Instead, you can directly use a non-string value as a parameter in append.
· Stringbufferinstantiationwithchar: stringbuffer sb = new stringbuffer ('C'); The Char will be converted into int to intialize stringbuffer size.
Translate stringbuffer using character initialization: stringbuffer sb = new stringbuffer ('C'); character C is converted to int value as the initialization size parameter of stringbuffer.
· Use1_stocomparestrings: Using '=' or '! = 'To compare strings only works if intern version is used on both sides
Use the equals method to compare strings: Use '=' or '! = 'Comparing the string size is only a reference to the constant pool on both sides.
· Avoidstringbufferfield: stringbuffers can grow quite a lot, and so may become a source of Memory Leak (if the owning class has a long life time ).
Avoid using the stringbuffer attribute in the class: the variable of the stringbuffer type can become very large, which may cause memory leakage. (If the host class has a long life cycle)