1
Answer

Write a method which will count the number of words in a file?

Sangeetha Haudakari

Sangeetha Haudakari

16y
5.3k
1

This was the question asked by one of the interviewers. I thought of using a File operations like use a stream reader to read each word  with space as a dilimeter and increase the count for each word but am not very sure how to implement a delimeter in my code?

OR

I think while reading word store them in an string /arraylist and find the length of the arraylist.

Which option you think is more optimized in terms of memory and other factors.

Any pointers/suggestions are higly appreciate.


Answers (1)