another array to use in another class?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: another array to use in another class?

  1. #1
    Join Date
    Sep 2010

    Question another array to use in another class?

    Hi. I have a reader class (code below) that just reads over a text file and puts items into a comma-delimited array. Items in the text file are int positionCode and String positionTitle, in the form:


    My question is: Is there a way to put ONLY the position codes (int) into a separate array?
    **I want to write a method in another class that finds the position code with the lowest value.**
    Is putting them in a separate array the best way or should I do it another way and how?

     * reads in an employee's position in a department into memory
    public class PositionReader {
    	private BufferedReader in;
    	private Company Company;
    	 * constructor
    	 * @param fileName
    	 * @throws FileNotFoundException
    	public PositionReader(String fileName, Company company) throws FileNotFoundException {
    		in = new BufferedReader(new FileReader(fileName));
    		this.Company = company;
    	 * reads a position from text file
    	 * @return position
    	public Position readPosition() {
    		String line;
    		try {
    			line = in.readLine();
    		if (line == null || line.trim().length() == 0) {
    			return null;
    		String[] fields = line.split(",");
    		int positionCode = Integer.parseInt(fields[0]);
    		String positionTitle = fields[1];
    		Position position = new Position(positionCode, positionTitle);
    		return position;
    		} catch (IOException e) {
    			return null;
    	public void close() throws IOException {

  2. #2
    Join Date
    Jun 1999
    SW Missouri

    Re: another array to use in another class?

    To put the codes into an array, you need to know how many there are.
    Where do you store the Position records that are returned by readPosition? Can the size of that be used to create the array and then make a pass over the Position records and extract the codes to the array.

    Why do you need a separate array of codes? Can your search routine look in the Position records for the value desired? That would make more sense.

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center