Passing an array variable from one method to the other

Discussion in 'Programmer's Corner' started by krow, Aug 18, 2011.

  1. krow

    Thread Starter Member

    May 25, 2010
    49
    0
    I know how to do this when I'm just dealing simple integer values, very simple example using Java:

    Code ( (Unknown Language)):
    1.  
    2. public class NewClass{
    3.  
    4.     public static void main(String[] args) {
    5.  
    6.         first();
    7.     }
    8. static void first(){
    9.  
    10.     String a = "Hello world";
    11.     second(a);
    12.  
    13.     }
    14.  static void second(String b){
    15.  
    16.      System.out.println(b);
    17.  
    18.     }
    19.  
    20. }
    21.  
    But how do I do the same when I have string arrays?

    Code ( (Unknown Language)):
    1.  
    2. public class NewClass{
    3.  
    4.     public static void main(String[] args) {
    5.  
    6.         first();
    7.     }
    8. static void first(){
    9.  
    10.     String a[] = {"mary", "peter", "john"};
    11.    
    12.     //????
    13.  
    14.     }
    15.  static void second(String b[]){
    16.  
    17.      //????
    18.  
    19.     }
    20.  
    21. }
    22.  
    I know I have to use FOR but I don't know how.

    Thanks a lot in advance!
     
Loading...