Faylda fərqli qiymətlərin müqayisəsi

Faylda dublikat qiymətlərin müqayisəsi üçün aşağıdakı java kod köməyinizə gələ bilər: Burada faylda olan bütün dublikat olanlar və tək olanlar hesablanacaq və nəticədə tək olanları çıxardacaq.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

public class comparation {
    public static void main (String  args[]) throws FileNotFoundException {
        Map<Integer, Integer> countMap = new HashMap<Integer, Integer>();
        List<Integer> myNumbers= new ArrayList();
        BufferedReader reader = new BufferedReader(new FileReader("D:/documents/excel_report/report_172.csv"));
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                myNumbers.add(Integer.parseInt(line));
            }
        for(int i=0; i<myNumbers.size(); i++){
            Integer myNum = myNumbers.get(i);
            if(countMap.get(myNum)!= null){
                Integer currentCount = countMap.get(myNum);
                currentCount = currentCount.intValue()+1;
                countMap.put(myNum,currentCount);
            }else{
                countMap.put(myNum,1);
            }
        }

        Set<Integer> keys = countMap.keySet();
        for(Integer num: keys){
            if (countMap.get(num).intValue()!=2){
            System.out.println(num.intValue()+" count="+countMap.get(num).intValue());
            }
        }

        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

Comments

Popular posts from this blog