java - How to compare array elements that are not parrallel while looping through the lines of a text file? -


I'm stuck with this argument. I have two text files that read programs, but I can not compare it to each other in the following way:

The first text file looks like this:

  1,01 / 04/14, APO, 14: 47: 53, 2,01 / 04/14, APO, 14: 48: 08, 3, 01/04/14, APO, 14: 48: 25, 7, 01/04/14, APO, 14: 53: 50,   

The second text file looks like this:

  1,01 / 04/14 , apo, 14: 47: 53, 2,01 / 04/14, APO, 14: 48: 08, 4, 01/04/14, APO, 14: 48: 25, 701 / 04/14, APO , 14: 53: 50,   

each line of text from each file The array is stored. I want to grab the first line of the first text file, the first array of the first line, which is "1" and compares the first array element of each row in the second file. Then grab the first array element of the second row of the first text file, which is "2" and compares the first array element of each row on the second text file.

I have done this so far:

  while ((TKP = tkpbr.readLine ()) = Null & amp; (tkn = tknbr.readLine ()) = Null) {tkparray = tkp.split (","); Int c = 0; (For string: tkparray) {//System.out.println ("value [" + c + "] =" + s); C ++; } Tknarray = tkn.split (","); int a = 0; For (string s: tnarra) {//System.out.println ("value [" + a + "] =" + s); One ++; } If (tkparray [0]. Material exoles (TNARA [0]) {System.out.println (tkparray [0] + "\ t" + tknarray [0]); }}   

This works, but if array elements are not equal or if text files are shown below it does not work:

The first text file It looks like:

  1,01 / 04/14, apo, 14: 47: 53, 2,01 / 04/14, apo, 14: 48: 08, 301/04 / 14, APO, 14: 48: 25, 7/01/14/14, APO, 14: 53: 50,   

The second text file looks like this:

  3,01 / 04/14, apo, 14: 47: 53, 701/4/14, apo, 14: 48: 08, 1,01 / 04/14, apo, 14: 48:   

Any help is appreciated!

There are several ways to do this

There is a way to create a class that is both files Formatting each row of each assume that each line is unique in one file (looking at the first number), set each set in each line and finally check the similarity.

  class date {private long id; Private date; Give a personal string; Do not forget to override // constructor and all accessories // Hashod} set & lt; Data & gt; DatasFileOne = new hashset & lt; & Gt; (); Set up & lt; Data & gt; DatasFileTwo = new hashset & lt; & Gt; (); SimpleDetermutation SDF = New SimpleDormat ("DD / MM / YY HH: mm: SS"); While ((TKP = tkpbr.readLine ()) = Null & amp; & amp; (tkn = tknbr.readLine ()) = Null!) {Tkparray = tkp.split (","); datasFileOne.add (what's for the same thing setFileTwo) (new data (Long.parseLong (tkparray [0]), sdf.format (tkparray [1] + "+ + tkparray [3]), tkparray [2]);} Boolean filesEquals = datasFileOne.equals (datasFileTwo);   

If you do not care about storing those values ​​in a POJO, you can use Files.readAllLines (If you are using Java 7).

  path p1 = // path to file a path p2 = // path file two charsets cs = // encoding list & Lt; string & gt; datasFileTwo = Files.r from the & lt; string & gt; datasFileOne = Files.readAllLines (p1, cs); eadAllLines (p2, cs); if (datasFileOne.size () == datasFileTwo.size ()) collections {collections.sort (datasFileOne); collections (datasFileTwo); if (datasFileOne.equals (datasFileTwo)) {// similar Content}} other {// similar content}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -