Make an arraylist of unique values I have, in Java, an arraylist with these values (many lines, this is just an extract):


  20/03/2013 23:31:46   6870    6810    6800    6720    6860    6670    6700    6650    6750    6830    34864   34272
  20/03/2013 23:31:46 6910    6780    6800    6720    6860    6680    6620    6690    6760    6790    35072   34496


where the first two values are strings that contain data and are stored in a single element.

What I want to do is to compare the string data elements and delete, for example, the second one and all the elements referred to that line.

For now, I've used a for cycle that every 13 elements compares the string (in order to compare only data strings).

Can I implement this with other better solutions?

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Downsampler {
    public static void main(String[] args) throws Exception{
        //The input file
        Scanner s = new Scanner(new File("prova.txt"));

        //Saving each element of the input file in an arraylist    
        ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
        while (s.hasNext()){
            list.add(s.next());
        }
        s.close();

        //Arraylist to save modified values
        ArrayList&lt;String&gt; ds = new ArrayList&lt;String&gt;();

        int i;
        for(i=0; i&lt;=list.size()-13; i=i+14){
            //combining the first to values to obtain data    
            String str = list.get(i)+" "+list.get(i+1);
            ds.add(str);
            //add all the other values to arraylist ds
            int j;
            for(j=2; j&lt;14; j++){
                ds.add(list.get(i+j));
            }

            //comparing data values
            int k;    
            for(k=0; k&lt;=ds.size()-12; k=k+13){
                ds.get(k); //first data string element    

                //Comparing with other strings and delete
                //TODO    
            }
        }
    }
}
To answer your question.. it depends on how you want to handle the data. Take a step back and put your self in the users shoes. Lets say the user has those numbers saved as bank account transactions.. He would want those numbers saved somewhere, but not necessarily visible. If that was the case you wouldn't want "delete" that data. You could, however, parse the data into say a table. You could give each cell in that table a class that has a boolean value called visible, and a int value. Then you could set a row or column to not visible as you wish. That would give you the ability to then just loop through the rows and columns and output the data as needed.