You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by tao jingrui <ta...@hotmail.com> on 2004/07/02 03:36:58 UTC

very wired String hashcode problem of HSSF

hi,friends

I am new to POI. I try to use HSSF to parse content from a excel file. But 
I met a very wired problem.

I want to extract String value from a excel file, and compare the String 
value with strings in a hashmap. Then decide whether the hashmap contains 
the String values in excel file. the problem is when I extract the String, 
for example "test", the hashcode of the string is different with the 
hashcode of string "test" in the hashmap.

that means the same content of strings have different hashcode!? who meet 
the similar problem? please help me, I very appreciate it. 

the following is snapshot of my code:

        //there is a "test" cell in file
        POIFSFileSystem fs = new POIFSFileSystem(new 
FileInputStream(file));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(isheetNum);

        //store data in the map
        Map excelMap = new HashMap();
        String test = "test";
        System.out.println("hashcode in map:"+test.hashcode());
        excelMap.set(test,"value");
        
        //(i,j)is the location of "test" cell
        HSSFRow row = sheet.getRow(i);
        HSSFCell cell = row.getCell(j);
        if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){
              String cellString=cell.getStringCellValue();
              System.out.println(cellString);
              System.out.println("hashcode in 
cxcel"+cellString.hashcode());
           }
        }

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com  


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org


Re: very wired String hashcode problem of HSSF

Posted by Danny Mui <da...@muibros.com>.
are you sure these strings are exactly the same?  are there whitespaces
appended/special characters?

tao jingrui wrote:

> hi,friends
> 
> I am new to POI. I try to use HSSF to parse content from a excel file. 
> But I met a very wired problem.
> 
> I want to extract String value from a excel file, and compare the String 
> value with strings in a hashmap. Then decide whether the hashmap 
> contains the String values in excel file. the problem is when I extract 
> the String, for example "test", the hashcode of the string is different 
> with the hashcode of string "test" in the hashmap.
> 
> that means the same content of strings have different hashcode!? who 
> meet the similar problem? please help me, I very appreciate it.
> the following is snapshot of my code:
> 
>        //there is a "test" cell in file
>        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
>        HSSFWorkbook wb = new HSSFWorkbook(fs);
>        HSSFSheet sheet = wb.getSheetAt(isheetNum);
> 
>        //store data in the map
>        Map excelMap = new HashMap();
>        String test = "test";
>        System.out.println("hashcode in map:"+test.hashcode());
>        excelMap.set(test,"value");
>               //(i,j)is the location of "test" cell
>        HSSFRow row = sheet.getRow(i);
>        HSSFCell cell = row.getCell(j);
>        if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){
>              String cellString=cell.getStringCellValue();
>              System.out.println(cellString);
>              System.out.println("hashcode in cxcel"+cellString.hashcode());
>           }
>        }
> 
> _________________________________________________________________
> 享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org