You are running into the problem of serialization. Serialization is where you convert some data into a format that can be transmitted. There are several ways of doing this, some are mentioned in other answers.
I would suggest using JSON as your format. You can get a nice JSON library for java from json.org. Then you can simply create a JSON array with the library and write it to the servlet's OutputStream.
public void service(ServletRequest req, ServletResponse res) {
final JSONArray arr=new JSONArray();
for (String s : this.myListOfStrings){
arr.put(s);
}
//Here we serialize the stream to a String.
final String output = arr.toString();
res.setContentLength(output.length());
//And write the string to output.
res.getOutputStream().write(output.getBytes());
res.getOutputStream().flush();
res.getOutputStream().close();
}
Now from your client, you can make the request and get back your ArrayList like so:
public ArrayList<String> contactServer(){
final URL url = new URL(serverURL);
final URLConnection connection=url.openConnection();
connection.setDoOutput(true);
/*
* ...
* write your POST data to the connection.
* ...
*/
final BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final char[] buffer=new char[Integer.parseInt(connection.getHeaderField("Content-Length"))];
int bytesRead=0;
while (bytesRead < buffer.length){
bytesRead += br.read(buffer, bytesRead, buffer.length - bytesRead + 1);
}
final JSONArray arr = new JSONArray(new String(buffer));
final ArrayList<String> ret = new ArrayList<String>(arr.length());
for (int i=0; i<arr.length(); i++) {
ret.add(arr.get(i));
}
return ret;
}