I'm having an issue with trying to figure out how to take two text files that contain strings (sorted in ascending order), and merge them into a third text file that is also sorted in ascending order. The problem is I can't use arrays and I shouldn't have to sort the strings. Also, the two text files are not necessarily the same length.
I've tried several times, but I can't seem to figure it out. Mainly, what I can't figure out is how to simultaneously read the two files together and then compare each line as they come in. I've tried using compareTo which works, but I have it set up in a while loop which is reading both files at the same time (ie. while (fileReader1.hasNext() && fileReader2.hasNext()).
I am not confusing anything but using the metric most widely used to describe the "biggest" companies or who are "worth" the most. I agree in general tech companies are overvalued. Are you trying to make some argument Apple isn't doing well financially? LOL They certainly are NOT desperate by any measure and even if they were this wouldn't be a reason why. It's just good old marketing via social media which all companies do.
Question
Zygar
Hey,
I'm having an issue with trying to figure out how to take two text files that contain strings (sorted in ascending order), and merge them into a third text file that is also sorted in ascending order. The problem is I can't use arrays and I shouldn't have to sort the strings. Also, the two text files are not necessarily the same length.
I've tried several times, but I can't seem to figure it out. Mainly, what I can't figure out is how to simultaneously read the two files together and then compare each line as they come in. I've tried using compareTo which works, but I have it set up in a while loop which is reading both files at the same time (ie. while (fileReader1.hasNext() && fileReader2.hasNext()).
Anyone have any ideas?
Link to comment
https://www.neowin.net/forum/topic/874284-java-merge-sorted-files/Share on other sites
2 answers to this question
Recommended Posts