Below is ugly hack. It concept but it not invoke any String methods.
import java.io.*;
import java.util.*;
public class Hello {
public static String reverceWithoutStringMethods(String word){
String result = "";
//------ Write string to file -----------
BufferedWriter writer = null;
try {
writer = new BufferedWriter( new FileWriter("tempfile"));
writer.write(word);
}
catch ( IOException e) {}
finally {
try{
if ( writer != null) writer.close( );
}
catch ( IOException e){}
}
//------ read string from file -------------
RandomAccessFile f=null;
try {
f = new RandomAccessFile("tempfile", "r"); // Open file
int length = (int) f.length(); // Get length
// Read file
byte[] data = new byte[length];
f.readFully(data);
// Reverse data
for (int i=data.length; i>=0; i--){
result += (char)data[i-1];
}
} catch(Exception e){}
finally {
try{
f.close();
}
catch (Exception e){}
}
return result;
}
public static void main(String[] args) {
System.out.println(reverceWithoutStringMethods("Test"));
System.out.println(reverceWithoutStringMethods(""));
}
}
Output:
tseT