Search code examples
javaarraysindexingquote

How to extract all information at a user specified index in an array, store for later


I have a problem needing arrays that contain information from a aCSV file, user needs select car number and that car number is used to extract car info from the specified index for printing. Any help in directing me would be greatly appreciated.

`while (input.hasNextLine()) {
                line = input.nextLine();
                carsAvailable++;
                int length = line.length();
                String fields[] = line.split(",");
                String CarNo = fields[0];
                String CarName = fields[1];
                String Seats = fields[2];
                String Transmission = fields[3];
                String CarType = fields[4];
                String RateDay = fields[5];
                ("enter a car no");`

*CarNo to determine index number*

quote any direction would be great


Solution

  • Create a car class which have all these fields. Then You can save carNumber as key in Map and car object in value. This way your search would be lot easier and quick.

    Somehow unable to add code so adding a pic for reference.enter image description here