473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Compare Contents of Two Files

Does anyone know how to compare contents of two ArrayLists? I want to compare them to see if they match up. Do you have an example or could you point me in the right direction. I know I need to loop through it with an if statement a for loop somehow or both, but I am not sure how. thanks for any help you can provide-
Nov 1 '07 #1
26 17316
r035198x
13,262 8TB
Does anyone know how to compare contents of two ArrayLists? I want to compare them to see if they match up. Do you have an example or could you point me in the right direction. I know I need to loop through it with an if statement a for loop somehow or both, but I am not sure how. thanks for any help you can provide-
The objects in the ArrayList are Comparable, right?
When you say you want to see if they "match up" you mean if they contain equal objects at the same locations, right?

Then a simple loop going through the ArrayLists should do it.
Nov 1 '07 #2
It is not that simple. I am trying to compare two separate documents, and find where the changes were made. I want to go through some type of loop to find the changes made on one comparred to the other. The contents may be moved all around.
Nov 1 '07 #3
r035198x
13,262 8TB
It is not that simple. I am trying to compare two separate documents, and find where the changes were made. I want to go through some type of loop to find the changes made on one comparred to the other. The contents may be moved all around.
That is not what you said in your original post is it? So these documents are what type? .txt, .odt, e.t.c?
Nov 1 '07 #4
They are both text files.
Nov 1 '07 #5
They are both text files.
I put them both in an ArrayList though.
Nov 1 '07 #6
r035198x
13,262 8TB
I put them both in an ArrayList though.
What kind of changes are you trying to look for.
It may be better to read the files into two StringBuilders. Open the specs for the StringBuilder class and see what can be done on it.
Nov 1 '07 #7
I just want to know the word changes of the two documents. Could I use the indexOf in a loop to notice the changes?
Nov 1 '07 #8
What about the contains method. What do you think?
Nov 1 '07 #9
r035198x
13,262 8TB
If you use contains, you would be testing to see if it contains what?
To test for word differences, just look word by word in the files and see if the words are the same.

OK Suppose you have the file initially as

Expand|Select|Wrap|Line Numbers
  1. this
  2. was the 
  3. file before
Then later it becomes
Expand|Select|Wrap|Line Numbers
  1. was this
  2. the
  3. file before
What should the program do?
Nov 1 '07 #10
I guess I just want to see the word differences for now. Do you know an looping algorithm for this??
Nov 1 '07 #11
r035198x
13,262 8TB
I guess I just want to see the word differences for now. Do you know an looping algorithm for this??
You haven't answered my question yet.
The answer determines what (if any) kind of a loop you need.
Nov 1 '07 #12
I am not sure exactly what I need when you put it this way. I will take a look at what I am doing, and see if I can clarify my questions. thanks for trying to help me-
Nov 1 '07 #13
JosAH
11,448 Expert 8TB
Have a look at the diff algorithm.
It implements the LCS (Longest Common Substring) algorithm in order to find
the minimal adjustments (inserts, updates, deletes) needed to transform one
text to the other text.

kind regards,

Jos
Nov 1 '07 #14
You all are great helpers! I really appreciate it!

Can I ask you about one more thing. I was reading about an inner and outer loop to compare items in arrays. Do you know where to find the algorithm for this, too? This might help me too!
Nov 1 '07 #15
r035198x
13,262 8TB
You all are great helpers! I really appreciate it!

Can I ask you about one more thing. I was reading about an inner and outer loop to compare items in arrays. Do you know where to find the algorithm for this, too? This might help me too!
You do realize that an inner loop is simply a loop started within another loop? There is no algorithm for it as such but the moment you start a loop inside another loop then that loop becomes an inner loop and the first one is the outer loop.
Nov 1 '07 #16
Yes, I have used it before, but I am not too sure about how it works to well. I was hoping someone could point me to a good article on it. I am not too familar with how it works, and I would like to better understand it.
Nov 1 '07 #17
r035198x
13,262 8TB
Yes, I have used it before, but I am not too sure about how it works to well. I was hoping someone could point me to a good article on it. I am not too familar with how it works, and I would like to better understand it.
Just go through Sun's tutorial.
Nov 1 '07 #18
I am pretty good with using one for statement in a program, but I get confused when I start using more than one. Do you have any good examples to point out for more than one?? Man, I have a lot to learn here!
Nov 1 '07 #19
r035198x
13,262 8TB
I am pretty good with using one for statement in a program, but I get confused when I start using more than one. Do you have any good examples to point out for more than one?? Man, I have a lot to learn here!
For that page that I gave you just hit next and you'll get to some parts where nested loops are used. You'll also learn some things there as well along the way. Also try out some programs that involve arrays and require nested loops. Things are generally easier to learn if you practice them on the compiler as well.
Nov 1 '07 #20
I see them now! I will take a look, and I will heed your advice on practice. I don't think I practice everything as much as I should!! Thanks again for all your help! You all are the Best!
Nov 1 '07 #21
JosAH
11,448 Expert 8TB
I don't want to discourage you but I'm afraid that a decent 'diff' algorithm is a bit
way over your head right now. First study what loops (within loops) are all about
and realize that they're nothing special. A largest common substring algorithm
(and an efficient implementation thereof) is out of reach for now.

kind regards,

Joa
Nov 1 '07 #22
I gotcha....your great help!!! thank you two -
Nov 1 '07 #23
JosAH
11,448 Expert 8TB
I gotcha....your great help!!! thank you two -
About those nested loops: think how you would visit all squares on a chessboard
or similar. Think of rectangular (non-square) boards; how would you visit all the
cells? Think of a loop per row and an inner loop per column. Try it the other way
around and see in what order the cells are visited. Try to do it with a single loop.
Print out all the index values and see what happens.

kind regards,

Jos
Nov 2 '07 #24
How to compare two files in java & uncommon thing should print in text file..

thanks
Samir
Feb 18 '08 #25
r035198x
13,262 8TB
How to compare two files in java & uncommon thing should print in text file..

thanks
Samir
Have you read this thread at all?
Feb 18 '08 #26
JosAH
11,448 Expert 8TB
How to compare two files in java & uncommon thing should print in text file..

thanks
Samir
Why ask again in someone else's thread? You also started your own thread for
your question. Stick to it please.

kind regards,

Jos
Feb 18 '08 #27

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Robin Siebler | last post by:
I have two directory trees that I want to compare and I'm trying to figure out what the best way of doing this would be. I am using walk to get a list of all of the files in each directory. I...
2
by: david | last post by:
hi: The file can be PDF or Word format. Any help? thx
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
5
by: | last post by:
What is the simplest way to determine if two files are identical (that is, all bytes the same). I want to check to see it the current version of a .jpg file is identical to the original. I wish...
2
by: Nitro | last post by:
Does anyone know a simple way to compare two images to see if they are the same? The filenames of the images will be different, but if the image data is the same I would like to test for that. ...
5
by: drabee | last post by:
Please help 2 things: 1-I need c# code to compare 2 audio files .or any other .net code 2-code to receive bluetooth file from mobile and save it using .net code
5
by: stamatis32 | last post by:
Hello everybody, i want to make a prog to compare the contents of 2 dirs. You can compare easily 2 files, but how this happend with dirs. I am very confused, i dont know where to start from, can...
0
by: mlco | last post by:
Pls help. I have 2 wafer maps file for comparison. The checking will only start after the "#" and ended with "##". The file contains; ERROR CODE OK WAFER ID 01 REFERENCE DIE ROWS 74
1
by: raj85 | last post by:
i want to compare 2 same files which is located at different location. i olready created 2 file browser button. now i juz need c# code to do comparing text of the both files. it muct check both...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.