Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to Check if the order of columns in two files is same?

I have two files containing columns names ,I need to validate if the columns are in the same order.

 

For eg : File1

ID;Name;Address

File2

ID:Address:Name

 

If these are the input files.I should be able to extract the columns which are in the wrong order.

Labels (2)
20 Replies
TRF
Champion II
Champion II

If you don't need to identify all the differences but just check if both header lines are identical, I suggest you to extract them and concatenate the values into a single string for each file giving something like "field1;field2;field3" for the 1rst file and maybe something like "field1;field3;field2" for the 2nd file. Then you can compare the strings.
Anonymous
Not applicable
Author

Is there any method to extract the specific columns that are not in order?

Anonymous
Not applicable
Author

Is there any method to extract the specific columns that are not in order?

TRF
Champion II
Champion II

In this case, use String.split() method for each header line then iterate over each array to compare element by element. As soon as you detect a difference, you have the field names.
Search for "java string split" with your preferred search engine.
TRF
Champion II
Champion II

In this case, use String.split() method for each header line then iterate over each array to compare element by element. As soon as you detect a difference, you have the field names.
Search for "java string split" with your preferred search engine.
Anonymous
Not applicable
Author

I understood the function but can you give me a example code for the iteration part and comparision part.I am not so good in java coding .
Anonymous
Not applicable
Author

I understood the function but can you give me a example code for the iteration part and comparision part.I am not so good in java coding .
TRF
Champion II
Champion II

Trying by yourself is the best way for learning.
Here is a link with a good example which will help you https://www.guru99.com/how-to-split-a-string-in-java.html
TRF
Champion II
Champion II

Trying by yourself is the best way for learning.
Here is a link with a good example which will help you https://www.guru99.com/how-to-split-a-string-in-java.html
Anonymous
Not applicable
Author

thank you!