Results 1 to 6 of 6
- 01-23-2012, 07:56 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 56
- Rep Power
- 0
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
- 01-23-2012, 09:24 PM #2
Member
- Join Date
- Aug 2011
- Posts
- 56
- Rep Power
- 0
Re: read or call an array from other class an method
any idea????????????
- 01-23-2012, 09:25 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
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 09:30 PM.
- 01-23-2012, 09:48 PM #4
Member
- Join Date
- Aug 2011
- Posts
- 56
- Rep Power
- 0
Re: read or call an array from other class an method
any example ????
- 01-23-2012, 10:04 PM #5
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
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.
- 01-23-2012, 10:42 PM #6
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Similar Threads
-
Inner class method call
By d915172 in forum New To JavaReplies: 3Last Post: 11-11-2010, 09:40 PM -
Trying to call a method from sub class
By TheNewGuy in forum New To JavaReplies: 4Last Post: 10-17-2010, 07:08 AM -
how call from inner class(anonymous or not), a method of parent class?
By lse123 in forum AWT / SwingReplies: 2Last Post: 05-01-2010, 08:59 AM -
How to call a method from another class?
By jboy in forum New To JavaReplies: 8Last Post: 09-09-2009, 07:29 AM -
How can I call my database read method to display its ArrayList?
By matpj in forum New To JavaReplies: 3Last Post: 01-29-2009, 10:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks