I am using a BufferedReader. I just wanna know how to clear the BufferedReader after every line is read values from keyboard. I am using like
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String male = br.readLine();
please help me out.
There is not really any reason to “clear” the String “buffer”. If you are worried about memory use, the String will automatically be garbage collected by the JVM when it is no longer used.
However,
will effectively remove the reference to the String. Strings are immutable, so you can’t modify the “buffer” and clear it, the best you can do is remove the reference to it and then have it garbage collected.
EDIT
To answer the question about BufferedReaders…
There is no need and no way to “clear” a BufferedReader. If you encounter an error, you can simply call readLine() again, and nothing you read before should have any effect. If you were reading from file and got an exception, you should check if you are at the end of the file, but because you are reading from keyboard, I would advise simply calling readLine() again.