0
Can any one send , simple example of string reverse????
5 Respuestas
+ 6
public static String reverse(String input)
{
char[] in = input.toCharArray();
int begin=0;
int end=in.length-1;
char temp;
while(end>begin)
{
temp = in[begin];
in[begin]=in[end];
in[end] = temp;
end--;
begin++;
}
return new String(in);
}
+ 1
basicly the same, but without the need of two variables for counting and no placeholder variable.
public static String reverse(String input)
{
char[] in = input.toCharArray();
char[] out = new char[in.length];
for(int i = 0; i < in.length; i++) {
out[i] = in[in.length - i -1];
}
return new String(out);
}
+ 1
Easiest method is to create a string buffer from the string and call the reverse method.
0
instead of doing all these.....you can directly use reverse method
0
yes you can see some examples in my code blog. their is String some examples you can understand easy.