D:\Sam\InterviewsMaterial\SiteWorx\SiteWorxTest\src\java\string_manipulation_services_package\ReverseString.java
 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 package string_manipulation_services_package;
 6 
 7 /**
 8  *
 9  * @author sameldin
10  */
11 public class ReverseString 
12 {
13     public ReverseString()
14     {
15         
16     }
17     /*
18      * 
19      */
20    public static String samQuickReverseString(String passedString)
21    {
22         String tempString = "";
23         tempString = new StringBuffer(passedString).reverse().toString();              
24         return tempString;
25    }    
26     /*
27      * 
28      */
29    public static String samQuickReverseString_2(String passedString)
30    {
31         return(new StringBuffer(passedString).reverse().toString());
32    }    
33     /*
34      * 
35      */
36    public static String samReverseString(String passedString)
37    {
38         if(     passedString == null 
39          ||     passedString.isEmpty())
40         {
41             return passedString;
42         }       
43         String tempString = "";
44         for(int index = passedString.length() -1;  index >=0; index--)
45         {
46             tempString = tempString + passedString.charAt(index);
47         }
48       
49         return tempString;
50     }
51     /*
52      * 
53      */
54     public String reverseRecursively(String passedString) 
55     {
56         if ((null == passedString) || (passedString.length() <= 1)) 
57         {
58             return passedString;
59         }
60         return reverseRecursively(passedString.substring(1)) + passedString.charAt(0);
61     }
62     
63     /**
64     * 
65     */
66    public static void main(String[] args) 
67    {
68         System.out.println("==================================\n");
69         ReverseString localReverseString = new ReverseString();
70         String x = "123456789";
71         System.out.println("x = " + x + " \n");
72         x = localReverseString.reverseRecursively(x);
73         System.out.println("x = " + x + " \n");
74         System.out.println("==================================\n");
75     }       
76     
77     
78 }
79