0

Following is the coding I currently have:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class DictionarySearch{

  public static void main(String[] args) throws IOException{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = "";
    List<String> dicts = new ArrayList<>();

    line = br.readLine();

    while (line != null && !(line.trim().isEmpty())) {
      dicts.add(line);
      line = br.readLine();
    }

    System.out.println("Done adding");
    String partial = br.readLine();
    System.out.println("Partial: " + partial);
  }
}

When I run my test, I place following values into console:

A
B
C

When I debug the code, dicts successfully contains String A and String B, but I cannot make partial equals to C. Is it means I using the wrong class to read the input from the console?

ArifMustafa
  • 4,617
  • 5
  • 40
  • 48
Vincent Zheng
  • 385
  • 1
  • 4
  • 19
  • you could use a do-while to avoid your using of readline() in two different places that ultimately serve the same purpose – RAZ_Muh_Taz Jan 08 '18 at 17:12
  • 1
    Is there a `newline` behind the `C`? – Timothy Truckle Jan 08 '18 at 17:13
  • I will prefer to use java.util.Scanner instead of BufferedReader. – ArifMustafa Jan 08 '18 at 17:14
  • [Seems fine here](https://ideone.com/KDmRb2). I'd also suggest [using a String instead of reading from the console](https://stackoverflow.com/questions/247161/how-do-i-turn-a-string-into-a-inputstreamreader-in-java) for the purposes of posting questions here, to allow for each reproducing and avoid any potential issues there. – Bernhard Barker Jan 08 '18 at 17:15

0 Answers0