Concept

How can arrays be passed to and returned from methods in Java?

ComputerScienceOne / Dynamic Memory

"We can pass and return arrays to and from methods in Java. We use the same syntax as when we define them by specifying a type and using square brackets. As an example, the following method takes an array of integers and computes its sum.\n\n1 /**\n\n2 * This method computes the sum of elements in the\n\n3 * given array which contains n elements\n\n4 */\n\n5 public static int computeSum(int arr[]) {\n\n6 int sum = 0;\n\n7 for(int i=0; i<size; i++) {\n\n8 sum += arr[i];\n\n9 }\n\n10 return sum;\n\n11 }"

Related Ideas

How can arrays be passed to and returned from methods in Java? | ComputerScienceOne | Bifalgorithm | Bifalgorithm