Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Tolls

Thread: reading and rewriting ( about String )

  1. #1
    silvathins is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Question reading and rewriting ( about String )

    Hi guys

    for example, there's a test.xlsx with 3 on A1, hello on B1

    my code is like below

    ---------------------------------------------------------------------

    InputStream inp = new FileInputStream("C:/work/test.xlsx");



    Workbook wb = WorkbookFactory.create(inp);
    Sheet sheet = wb.getSheetAt(0);
    Row row = sheet.getRow(0);
    Cell cell = row.getCell(0);



    if(cell.getNumericCellValue() == 3) // A1 에 있던 숫자가 3 이랑 같냐?
    System.out.println("3 is 3");
    else
    System.out.println("3 is not 3");



    cell=row.getCell(1);

    if(cell.getStringCellValue() == "hello") // A2 에 있던 문자가 hello 랑 같냐?
    System.out.println("hello is hello");
    else
    System.out.println("hello is not hello");

    ----------------------------------------------------------------------------------

    Result I expected is that

    3 is 3
    hello is hello

    but the actual result is that

    3 is 3
    hello is not hello

    Could you explain what the matter is?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: reading and rewriting ( about String )

    You don't use '==' to compare objects (eg Strings).
    You need to use equals().
    '==' will only return true if both Strings are actually the same object, not whether they have the same value.
    silvathins likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. rewriting a recursive function
    By Wnt2bsleepin in forum New To Java
    Replies: 6
    Last Post: 04-19-2012, 05:48 PM
  2. Arguments for/against rewriting API classes/methods?
    By Diargg in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2012, 03:18 PM
  3. Reading characters into a string
    By Teclis in forum New To Java
    Replies: 2
    Last Post: 03-08-2011, 10:08 PM
  4. Replies: 0
    Last Post: 01-13-2011, 10:58 AM
  5. url rewriting
    By jithan in forum Java Servlet
    Replies: 2
    Last Post: 06-23-2008, 06:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •