Answers for "How to return a String array in Java"

11

how do you make a method that returns an array java

public static int[] numbers()  
{  
int[] arr={5,6,7,8,9};  //initializing array  
return arr;  
}
Posted by: Guest on March-11-2020
0

How to return a String array in Java

import java.util.*;
public class Main
{
public static String[] return_Array() {
       //define string array
       String[] ret_Array = {"Java", "C++", "Python", "Ruby", "C"};
      //return string array
      return ret_Array;
   }
 
public static void main(String args[]) {
      //call method return_array that returns array   
     String[] str_Array = return_Array();
     System.out.println("Array returned from method:" + Arrays.toString(str_Array));
 
    }
}
Posted by: Guest on August-23-2021

Code answers related to "How to return a String array in Java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language