Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

RE: Java - Backwards - Second Draft


[Replies] [Reply] [View by Thread] [Help]
[Back To SNEAK Development Forum]

Posted by Ret. Gen D-Cypell On 2005-02-26 19:22:23
In Reply to Java - Backwards - Second Draft Posted by Cpt SAJChurchey On 2005-02-24 20:18:01

Ret. Gen
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:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.09475 seconds


About Us | Privacy Policy | Mission Statement | Help