Without using Collection Methods How can i get Reverse Format of String Like Raja as AJAR
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, April 30, 2007 03:20 AM


Without using Collection Methods How can i get Reverse Format of String Like Raja as AJAR

Re: Without using Collection Methods How can i get Reverse Format of String Like Raja as AJAR

Posted By:   java_learner  
Posted On:   Monday, April 30, 2007 06:50 AM

Hi Raja Ande,




See the below code for the reverse ot the String







public class ReversePrg {


public static void main(String[] args) throws Exception{



String str = "RajaAnde";


System.out.println("Before Reverse the string is : "+str);


char c[] = str.toCharArray();


int len =c.length;


char c1 = '\'';




for(int i= len;i>len/2;i--){


c1 = c[i-1];


c[i-1] = c[len-i];


c[len-i] = c1;


}


System.out.println("After Reverse the string is : "+new String(c));


}


}



Thanks,


Rajasekhar

Re: Without using Collection Methods How can i get Reverse Format of String Like Raja as AJAR

Posted By:   Anonymous  
Posted On:   Monday, April 30, 2007 04:32 AM

Hi
U can use StringBuffer class reverse method to reverse string

eg.StringBuffer sb = new StringBuffer("raja");
String rev = sb.reverse();

it will return string in reverse format

regards
vijay
About | Sitemap | Contact