Friday 5 February 2016

Reverse of a string without using predefined api and with api

1.with API methods/predefined method
======================================
package blog;

public class ReverseStringWithApi {

public static void main(String[] args) {

String string="Selenium Ramesh";
     String reverse = new StringBuffer(string).
     reverse().toString();
     System.out.println("String before reverse: "+string);
     System.out.println("String after reverse: "+reverse);
}

}

2.without API:
=================
package blog;

public class ReverseStringWithOutApi {

public static void main(String[] args) {

String string="Selenium Ramesh";
String reverseString="";
 
for(int i=string.length()-1;i>=0;--i){
reverseString +=string.charAt(i);
}
 
System.out.println(reverseString);
}


}

No comments:

Post a Comment