简体   繁体   中英

Java: How to read csv files of different data types and lengths into an ArrayList< Object>?

I have created a parent class Object with 3 parameters, a child class ObjectA with 4 parameters and a child class ObjectB with 8 parameters. These parameters have different data types. I need to read a csv file A (with 4 columns) and a csv file B (with 8 columns) into one ArrayList< Object>. Is this possible?

Yes, it's possible, except that the parent class cannot be called 'Object'.

    ArrayList<ObjectParent> list = new ArrayList<ObjectParent>();
    list.add(new ObjectA(aPath));
    list.add(new ObjectB(bPath));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM