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

Multi tool use
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);
}
}
java
marked as duplicate by user7294900, dasblinkenlight
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.
add a comment |
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);
}
}
java
marked as duplicate by user7294900, dasblinkenlight
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.
add a comment |
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);
}
}
java
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
java
edited Dec 30 '18 at 14:14
Hurtlocker
asked Dec 30 '18 at 12:02
HurtlockerHurtlocker
11
11
marked as duplicate by user7294900, dasblinkenlight
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
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You should compare with empty string if(!"".equals(dishName)){
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should compare with empty string if(!"".equals(dishName)){
add a comment |
You should compare with empty string if(!"".equals(dishName)){
add a comment |
You should compare with empty string if(!"".equals(dishName)){
You should compare with empty string if(!"".equals(dishName)){
answered Dec 30 '18 at 12:05
wardziniakwardziniak
895415
895415
add a comment |
add a comment |
jsKH4IJmPp7Yt1,ADo8iSj,jI3w OsIW,6IwH,7RY VQm,xCPgZytMCNB9cAj,HE,dHzphA,U0r38Y,muK,CZlc1uNLTRTOMNgQrb Mb