RE: Java - Backwards - Second Draft |
||
![]() Tr flamebalrog On 2005-02-24 20:18:01, SAJChurchey wrote > >public static String Backwards(String str){ > if(str == null || str.trim().equals("")) > return ""; > str = str.trim(); > StringBuffer newString = new StringBuffer(str); > return newString.reverse().toString(); >} > A not-null-and-not-empty-and-not-space-only String (one that will be reversed) is trimmed twice with your code (1st to test it, 2nd after the test). You could avoid it. Also, I think ' "literalString".equals(expression) ' is faster than ' expression.equals("literalString") '...can anyone confirm ? - Is it a feature or a bug ? - Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.02264 seconds |