Why this string comparison code of mine is not working? [duplicate]

Multi tool use
Multi tool use












0
















This question already has an answer here:




  • Should I use string.isEmpty() or “”.equals(string)?

    6 answers




if I do not input any string value on the text field error message should be displayed but the case here is exactly opposite. I mean run message is being displayed. May I know what is wrong with my code here?



private void searchButton1ActionPerformed(java.awt.event.ActionEvent evt) {



    String dishName = dishSearch.getText();

int count = 0;
String addName = " ";
if ("".equals(dishName)) {
JOptionPane.showMessageDialog(this, "Error");
} else {
for (int i = 0; i < menuTable1.getRowCount(); i++) {
if (menuTable1.getValueAt(i, 1) == dishName) {
count += 1;
addName += menuTable1.getValueAt(i, 2) + ", ";
}
}
JOptionPane.showMessageDialog(this, "There are " + count + " " + dishName + " dishes " + addName);
}



}









share|improve this question















marked as duplicate by user7294900, dasblinkenlight java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 30 '18 at 12:07


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • Should I use string.isEmpty() or “”.equals(string)?

      6 answers




    if I do not input any string value on the text field error message should be displayed but the case here is exactly opposite. I mean run message is being displayed. May I know what is wrong with my code here?



    private void searchButton1ActionPerformed(java.awt.event.ActionEvent evt) {



        String dishName = dishSearch.getText();

    int count = 0;
    String addName = " ";
    if ("".equals(dishName)) {
    JOptionPane.showMessageDialog(this, "Error");
    } else {
    for (int i = 0; i < menuTable1.getRowCount(); i++) {
    if (menuTable1.getValueAt(i, 1) == dishName) {
    count += 1;
    addName += menuTable1.getValueAt(i, 2) + ", ";
    }
    }
    JOptionPane.showMessageDialog(this, "There are " + count + " " + dishName + " dishes " + addName);
    }



    }









    share|improve this question















    marked as duplicate by user7294900, dasblinkenlight java
    Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Dec 30 '18 at 12:07


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • Should I use string.isEmpty() or “”.equals(string)?

        6 answers




      if I do not input any string value on the text field error message should be displayed but the case here is exactly opposite. I mean run message is being displayed. May I know what is wrong with my code here?



      private void searchButton1ActionPerformed(java.awt.event.ActionEvent evt) {



          String dishName = dishSearch.getText();

      int count = 0;
      String addName = " ";
      if ("".equals(dishName)) {
      JOptionPane.showMessageDialog(this, "Error");
      } else {
      for (int i = 0; i < menuTable1.getRowCount(); i++) {
      if (menuTable1.getValueAt(i, 1) == dishName) {
      count += 1;
      addName += menuTable1.getValueAt(i, 2) + ", ";
      }
      }
      JOptionPane.showMessageDialog(this, "There are " + count + " " + dishName + " dishes " + addName);
      }



      }









      share|improve this question

















      This question already has an answer here:




      • Should I use string.isEmpty() or “”.equals(string)?

        6 answers




      if I do not input any string value on the text field error message should be displayed but the case here is exactly opposite. I mean run message is being displayed. May I know what is wrong with my code here?



      private void searchButton1ActionPerformed(java.awt.event.ActionEvent evt) {



          String dishName = dishSearch.getText();

      int count = 0;
      String addName = " ";
      if ("".equals(dishName)) {
      JOptionPane.showMessageDialog(this, "Error");
      } else {
      for (int i = 0; i < menuTable1.getRowCount(); i++) {
      if (menuTable1.getValueAt(i, 1) == dishName) {
      count += 1;
      addName += menuTable1.getValueAt(i, 2) + ", ";
      }
      }
      JOptionPane.showMessageDialog(this, "There are " + count + " " + dishName + " dishes " + addName);
      }



      }




      This question already has an answer here:




      • Should I use string.isEmpty() or “”.equals(string)?

        6 answers








      java






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 30 '18 at 14:14







      Hurtlocker

















      asked Dec 30 '18 at 12:02









      HurtlockerHurtlocker

      11




      11




      marked as duplicate by user7294900, dasblinkenlight java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 30 '18 at 12:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by user7294900, dasblinkenlight java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 30 '18 at 12:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          You should compare with empty string if(!"".equals(dishName)){






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You should compare with empty string if(!"".equals(dishName)){






            share|improve this answer




























              0














              You should compare with empty string if(!"".equals(dishName)){






              share|improve this answer


























                0












                0








                0







                You should compare with empty string if(!"".equals(dishName)){






                share|improve this answer













                You should compare with empty string if(!"".equals(dishName)){







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 30 '18 at 12:05









                wardziniakwardziniak

                895415




                895415















                    jsKH4IJmPp7Yt1,ADo8iSj,jI3w OsIW,6IwH,7RY VQm,xCPgZytMCNB9cAj,HE,dHzphA,U0r38Y,muK,CZlc1uNLTRTOMNgQrb Mb
                    7 IjRywdkty1goE

                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas