RE: Java - Backwards - Second Draft |
||
![]() Ret. Gen D-Cypell My version.. public String backwards(String input)
{
if(input == null)
{
throw new IllegalArgumentException("null not supported");
}
StringBuffer buffer = new StringBuffer(input);
buffer.reverse();
return buffer.toString().trim();
}
You can thrown in an empty string check if you like, it wont change the output and the performance benefit will be pretty negliable.
Also in reality we should probably throw the exception when null is passed to any of the methods, rather than do this check every time, it would be best to factor it into the common superclass. 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(); >} > Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.09475 seconds |