You are not logged in. Please login at www.codechef.com to post your questions!

×

Discussion on Java and some tips

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 :-)

asked 01 Jan '15, 17:44

infam0us's gravatar image

0★infam0us
2125
accept rate: 0%

edited 01 Jan '15, 17:48


I've found that using ArrayList in Java is more efficient than using an Array most of the time because you can add() how many ever elements you want to it without having to specify the number of elements during declaration. For ArrayList, you can use Collections.sort() for sorting.

Is it true that BufferedReader and PrintWriter are faster than Scanner and System.out.print()? If so, I would like to start using them from now on...

link

answered 02 Jan '15, 15:57

data2000's gravatar image

3★data2000
12
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,288
×934
×715
×394
×242
×142
×69

question asked: 01 Jan '15, 17:44

question was seen: 2,886 times

last updated: 02 Jan '15, 22:26