Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.1k points)

I want to read a file that has 8 columns of data and want to store each string of data into an array. But it's displaying: Unable to find symbol error for employee.length. Within the row, I have placed 8 elements. 

This is my code. Kindly tell me where I am going wrong and also rectify it.

Scanner scan = new Scanner(new FileReader ("payrollData.dat"));

    String employee[] = new String[8];

    while(scan.hasNext())

    {   

        for(int i = 0; i < employee.length(); i++)

        {

            employee[i] = scan.next();

        }

    }

    System.out.println(employee);8

1 Answer

0 votes
by (11.7k points)

Well, you have written employee.length() which is wrong here, instead use employee.length.

When it's about the array, length is a final variable not a method. 

And also use Arrays.toString(employee) to properly print employees. 

System.out.println(employee) will only print reference addresses

If you want to become Java expert, you can check out the tutorials from Intellipaat from here.

Related questions

0 votes
1 answer
asked Mar 6, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Jul 9, 2019 in Java by Nigam (4k points)
0 votes
1 answer
asked Jul 9, 2019 in Java by Aditya98 (1.3k points)

Browse Categories

...