0

l am trying to store string values in an ArrayList and then print them to a file but my code is showing some errors of cannot find symbol. Where have l gone wrong. The following is my code.

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Arrays{
    public static void main(String[] args)throws IOException
    {
        File f = new File("C:\\Users\\Administrator\\Documents\\java code\\Arrays.txt");
        FileWriter fw = new FileWriter(f,true);
        PrintWriter pw = new PrintWriter(fw);

        ArrayList<String> header = new ArrayList<>(Arrays.asList("NAME","REGNUM","ACADEMICYEAR","PROGRAMME","COURSECODE","ASS1","ASS2","ASS3","TEST1","AGGREGATEDMARK","COURSEWORK","GRADE","RESULT"));

        pw.print(header);
        pw.close();

        }
    }

1 Answers1

1

Arrays class name is having conflict. Arrays.asList() is from java.util package. The class name is also Arrays. So Java is looking for a method called asList() from the current class, which does not exist.

Change the class name from Arrays to say PrintArrays.

Or use this code to explicitly tell to use java.util.Arrays.

ArrayList<String> header = new ArrayList<>(java.util.Arrays.asList("NAME","REGNUM","ACADEMICYEAR","PROGRAMME","COURSECODE","ASS1","ASS2","ASS3","TEST1","AGGREGATEDMARK","COURSEWORK","GRADE","RESULT"));
anantha ramu
  • 171
  • 4