Results 1 to 6 of 6
  1. #1
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    79
    Rep Power
    0

    Default read or call an array from other class an method

    Hello,

    I want to ask how can i read an array from other class and method.

    i have this classes.

    listPlayer.java
    Java Code:
    import java.io.*;
    
    public class  ListPlayers{
    	public static void dirlist(String fname){
    		File dir = new File(fname);
    		String[] chld = dir.list();
                   
                    
    		if(chld == null){
    			System.out.println("Specified directory does not exist or is not a directory.");
    			System.exit(0);
    		}else{
                        System.out.println("The Tournament Player List :");
    			for(int i = 0; i < chld.length; i++){
    				String fileName = chld[i];
    				System.out.println(i+" "+fileName);
    			}
    		}
                
                    System.out.println("End of Player List\n");
    	}
    }


    test.java

    Java Code:
    public class  readthearray{
    
         public static void main(){
                 for (int iii = 0; iii < 10; iii++) {
                         System.out.println(chld[iii]);
                    }
          }
    
    }

    in the second class i want to display the all the content of the chld[] array from the listPlayer.java class.
    how i have to do it.


    thank toy in advanced

  2. #2
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    79
    Rep Power
    0

    Default Re: read or call an array from other class an method

    any idea????????????

  3. #3
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: read or call an array from other class an method

    Like any other object.
    When You create an array, You actually create reference variable that points to instance of Array class, which is object.

    So, question is, how can You access variable from classes and methods?
    It depends on how You declared that variable(modifiers), and its location.
    Last edited by diamonddragon; 01-23-2012 at 10:30 PM.

  4. #4
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    79
    Rep Power
    0

    Default Re: read or call an array from other class an method

    any example ????

  5. #5
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: read or call an array from other class an method

    friend, I recommend you read about:
    - Local variable.
    - Variables of class.
    - Methods to return.
    - Methods of no return.

  6. #6
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: read or call an array from other class an method

    Quote Originally Posted by ki_ha1984 View Post
    any example ????
    Java Code:
    public class MyClass {
       public static String[] myArray;
    }
    
    public class TestMyClass {
       public static void main(String[] args) {
          MyClass.myArray = new String[5];
    }
    }

Similar Threads

  1. Inner class method call
    By d915172 in forum New To Java
    Replies: 3
    Last Post: 11-11-2010, 10:40 PM
  2. Trying to call a method from sub class
    By TheNewGuy in forum New To Java
    Replies: 4
    Last Post: 10-17-2010, 08:08 AM
  3. Replies: 2
    Last Post: 05-01-2010, 09:59 AM
  4. How to call a method from another class?
    By jboy in forum New To Java
    Replies: 8
    Last Post: 09-09-2009, 08:29 AM
  5. Replies: 3
    Last Post: 01-29-2009, 11:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •