Shaydoth Shaydoth - 1 year ago 128
Java Question

Using something other than an ArrayList

I have a problem which requires me to create an array that will store the name of a file, and then its contents. I tried to use this, to create an Array

ArrayList<String, String> fileContent = new ArrayList<String, String>();
but it calls an error, that there are an incorrect number of arguments. Whats the best way to get around this problem?

Would it be better to make two Arrays, one that stores the names, and one that stores the data in the file. Or is there another inbuilt thing inside of java that would be better to use?

Answer Source

create a custom class

class MyClass{
  String filename;
  String content;

// use methods as you want

then use array list for MyClass

ArrayList<MyClass> fileContent = new ArrayList<MyClass>();