-4

I've been having this problem.. I read with HSSF xls cell (which value is lets say "turbox" value this way:

 String hssfstanskup = sheet.getRow(p).getCell(3).getStringCellValue();

then, I create a row in my JTablel like this:

 model.addRow(new Object[] { hssfstanskup } );

but if I create if statement like this:

 if((String) tprojekty.getValueAt(0,1) == "xxx"){

it doesnot work...

extra info: tprojekty = new JTable(model); can anyone help me with this? thanks in advance!

Maximin
  • 1,655
  • 1
  • 14
  • 32
wild_pirate
  • 1
  • 1
  • 3
  • 6
    Take a look at [how-do-i-compare-strings-in-java](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Pshemo Apr 02 '13 at 11:57
  • 2
    Did you try searching anywhere? String comparison requires you to use `equals` method. – Rohit Jain Apr 02 '13 at 11:57

2 Answers2

1

If I am not wrong, you have to use the .equals() instead of ==

if((String) tprojekty.getValueAt(0,1).equals("xxx")) {
Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
Eveli
  • 498
  • 1
  • 6
  • 27
1

In order to compare strings in java you use the .equals() method instead of ==.

Please try:

if((String) tprojekty.getValueAt(0,1).equals("xxx"))

which should solve your problem! The answer for this could have been found though with a simple Google search, or checking previous posts on StackOverflow! So in future take a look around for a solution before you post a question.

Hayden
  • 2,818
  • 2
  • 22
  • 30
  • There is no need to cast returned value from `getValueAt` to String since every Object has `equals` method and thanks to polymorphism if returned object will be String code of `equals` will be taken from String class. – Pshemo Apr 02 '13 at 12:12