-1

how? enter code here Split the read line into parts; Create a brand from input data(parts); Add the brand to this list;

     ArrayList<String> str1 = new ArrayList<>();
    loadFromFile(file, str1);    
    for (String string : str1) {
        String[] str = string.split(",");
        //EG line of file: B7-2018, BMW 730Li (2018), Harman Kardon, 3.749
        String id,name,sound;
        double price;

        id = str[0];
        name = str[1];
        price = Double.valueOf(str[3]);
         sound = str[2];
        Brands brand = new Brands(id, name, sound, price);
        this.add(brand);  /// this is arraylist of Brands (extends ArrayList Brands)
        //error code: ArrayIndexOutOfBoundsException 
        //I do not understand this
hoang_Liu
  • 1
  • 1

1 Answers1

-1

You need to read the file with a Scanner and use String.split on your line to get your data

Hakan Dilek
  • 2,178
  • 2
  • 23
  • 35
g00se
  • 3,207
  • 2
  • 5
  • 9
  • Can you be more specific? How to read the file with a Scanner and use String.split ? EG for me ,plsss – hoang_Liu Jul 04 '21 at 13:30
  • i think ,my problem isn't read the file that is split and release to arraylist . rerror code is ArrayIndexOutOfBoundsException – hoang_Liu Jul 04 '21 at 13:58