包含方法不工作HashSet Java

时间:2017-03-27 22:51:56

标签: java excel apache-poi

所以我的包含方法存在问题。我打印出哈希集,它打印出两个[]之间的所有字符串。防爆。 [你好]。当我检查我的hashset是否具有特定的单元格值(试图删除重复的行)时,即使我在打印出hashset时可以看到hashset中的重复项,我的contains也会返回false。这是代码。

public class readInExcel {
static void readExcel() throws IOException
{

    JFileChooser fileChooser = new JFileChooser();

    FileNameExtensionFilter filter = new FileNameExtensionFilter(
    "xls","xlsx");

    fileChooser.setFileFilter(filter);

    fileChooser.setCurrentDirectory(new 
    File(System.getProperty("user.home")));

    int returnVal = fileChooser.showOpenDialog(new JPanel());

    if(returnVal == JFileChooser.APPROVE_OPTION)
    {   
        File OGFile = fileChooser.getSelectedFile();

        String fileName = "user.home.Desktop";

        InputStream is = new FileInputStream(OGFile);
        XSSFWorkbook wb = new XSSFWorkbook(is);

        XSSFSheet sheet = wb.getSheetAt(0);
        ArrayList<Form> vipList = new ArrayList<>();
        Iterator<Row> rowIterator = sheet.iterator();

        while (rowIterator.hasNext()) 
        {            
            Row row = rowIterator.next();
            int rowNumber = 1;

            Iterator<Cell> cellIterator = row.cellIterator(); 

            HashSet data = new HashSet();

            while (cellIterator.hasNext())  
            {
                XSSFRow currentRow;
                Cell cell = cellIterator.next();
                if(cell.getColumnIndex() == 18)
                {

          System.out.println(data.contains(cell.getStringCellValue()));
                    if(data.contains(cell.getStringCellValue()))
                    {
                        System.out.println("in contains check");
                        currentRow = sheet.getRow(rowNumber);
                        sheet.removeRow(currentRow);
                    }
                    else
                        data.add(cell.getStringCellValue());
                    //System.out.println(data);
                }   
            }
            rowNumber ++;
        }
    }
}

}

0 个答案:

没有答案