'Difference in time complexity between storing data as a HashMap and record instance

For one of my school assigments, I have to parse GenBank files using Java. I have to store and retrieve the content of the files together with the extracted information maintaining the smallest time complexity possible. Is there a difference between using HashMaps or storing the data as records? I know that using HashMaps would be O(1), but the readability and immutability of using records leads me to prefer using them instead. The objects will be stored in an array.

This my approach now

public static GenBankRecord parseGenBankFile(File gbFile) throws IOException {
    try (var fileReader = new FileReader(gbFile); var reader = new BufferedReader(fileReader)) {
        String organism = null;
        List<String> contentList = new ArrayList<>();

        while (true) {
            String line = reader.readLine();
            if (line == null) break; //Breaking out if file end has been reached

            contentList.add(line);
            
            if (line.startsWith("  ORGANISM  ")) {
                // Organism type found
                organism = line.substring(12);  // Selecting the correct part of the line
            }
        }
        // Loop ended
        var content = String.join("\n", contentList);
        return new GenBankRecord(gbFile.getName(),organism, content);
    }
}

with GenBankRecord being the following:

record GenBankRecord(String fileName,String organism, String content) {
    @Override
    public String toString(){
        return organism;
    }
}

Is there a difference between using a record and a HashMap, assuming the keys-value pairs are the same as the fields of the record?

String current_organism = gbRecordInstance.organism();

and

String current_organism = gbHashMap.get("organism");


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source