I have found that the BufferedReader is faster than the Scanner at taking inputs. My program was getting TLE with Scanner and as soon as I switched to BufferedReader, it ran perfectly well. Same goes with PrintWriter. My program which was getting TLE with System.out.print ran perfectly when I used PrintWriter instead. Will this be true for all programs? Can I save execution time by using BufferedReader and PrintWriter?
I have seen many programmers who import library classes one by one instead of the whole. I mean they write,“import java.io.BufferedReader; import java.io.PrintWriter;”. I always write,“import java.io.*;”. This imports the entire IO library. Does importing only the required libraries save time/memory or both?
What are some other ways I can reduce the execution and memory required in Java?
If you guys know some quick tips or techniques in Java that are helpful, please write them for every Java programmer.
I’ll start by saying Arrays.sort() is the best way to sort an array(even Strings).
Thanks a lot