Java Servlet program to separate Image Strings using Array or Array List

In my java servlet program i am getting images from android application.I want to encode again decode image. If i got two images from android: [abc,def].It is decoded using MyHelper.decodeImage1(a). Now problem comes in next step. I want to encode decoded image again. Yes it do encoding. But result is in a single string abcdef. How can i separate two images to send it back to android? How should i manage loop or array in loop. I have tried alot but can't differentiate abc and def. Please help

 String imageString=request.getParameter("image");
 // image comees in format [abc,def,efg... and son on]

        imageString=imageString.replace("[", "");
        imageString=imageString.replace("]", "");
        imageString=imageString.replace(" " , "");

        String[] r = imageString.split(",");

for(int i=0; i<r.length;i++){

                String a=r[i];
                System.out.println("In loop = "+i);

                byte[] imageByteArray = MyHelper.decodeImage1(a);

            String encodedimageByteArray=Base64.encodeBytes(imageByteArray) ;
            ArrayList<String> StringImages =  new ArrayList<String>();
            StringImages.add(encodedimageByteArray);
            response.getWriter().write(encodedimageByteArray);


                }
Jon Skeet
people
quotationmark

All you need to do is call write appropriately with the text you want to write. For example:

Writer writer = response.getWriter();
writer.write("[");
for (int i = 0; i < r.length; i++) {
     if (i != 0) {
         writer.write(","); // Separate this item from the previous one
     }
     byte[] bytes = MyHelper.decodeImage1(r[i]);
     String base64 = Base64.encodeBytes(bytes);
     writer.write(base64);
}
writer.write("]");

people

See more on this question at Stackoverflow