One method works too slowly (about 1.5 seconds, the text length is 460 characters; you need as little as possible). It is quite possible as a result of the error in the code. Can code with such functionality work faster?
public static double calcIndexTrigrams(String str) throws IOException { int nG=3; double index = 0; File file = new File(TRIGRAMS); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_16)); String line; for (int c = 0; c < (str.length()-nG); c++) { reader.mark((int) file.length()); while((line = reader.readLine())!= null){ if (str.substring(c,c+nG).equalsIgnoreCase(line.substring(0,nG))) { index+=(Double.parseDouble(line.substring(nG+1))); break;}} reader.reset();} return index;}