0

I have an array storing few int numbers. I want to pass this array into the server side so that the server can calculate the sum of the numbers inside the array and send back the results into the client. How could I do that?

public static void main(String args[]) {

    int[] num = new int[]{0,1,2,3};

    if(msg.equalsIgnoreCase("num")){ // msg is user input
        // send that array to the server       
    }

}
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Esha
  • 435
  • 2
  • 5
  • 12

1 Answers1

0

To send something via a network, you need to serialize it somehow. For a simple case like this, you can even do it manually (by converting it to a comma separated list, for example)

A better approach is to use a well-known data-interchange format, such as JSON. You can find many examples online on how to serialize to JSON and de-serialize using popular libraries like Gson and Jackson.

Amila
  • 5,195
  • 1
  • 27
  • 46