Compare two CSV files using JAVA with the condition to Ignore particular column in both

1,674 views
Skip to first unread message

Hrishikesh Mangle

unread,
Mar 1, 2018, 5:47:14 AM3/1/18
to Selenium Users
Hello Guys,

The ultimate motive here is to compare two CSV files using JAVA.
I have two CSV files (contains for example 10 columns). Among 10, one of the column contains Date-Time value (files are generated at different time), hence it will never match. I have to compare these two files ignoring Date-Time column. 
Any help over this would be highly appreciated. Thanks!

Krishnan Mahadevan

unread,
Mar 1, 2018, 9:48:28 PM3/1/18
to seleniu...@googlegroups.com

Your question has got nothing to do with Selenium. Please help keep this forum relevant by posting queries that are ONLY related to Selenium Webdriver.

 

To fix your issue here’s what you should be doing:

 

  1. Build a POJO that represents one row of data in your CSV file.
  2. Add a hashCode() and equals() implementation to your POJO that ignores the fields that you don’t want to compare, for its computation.
  3. Load the elements from first CSV file into a list (perhaps sort them as well).
  4. Repeat (3) for elements from second CSV file.
  5. For every element of list from (3) run a List2.contains() and ensure you always get a “true”. A false means that they are not equal.

I believe there are libraries such as assertj which lets you run equality checks amidst two collections as well.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
selenium-user...@googlegroups.com.
To post to this group, send email to
seleniu...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/1f42919c-936f-4df2-b3fd-c017f5000dc4%40googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Hrishikesh Mangle

unread,
Mar 2, 2018, 12:29:56 AM3/2/18
to Selenium Users
Got it! Thanks for your kind help!
Reply all
Reply to author
Forward
0 new messages