Skip to main content
adjusted title & ags to reflect the actual problem
Link
user207421
  • 311.9k
  • 45
  • 324
  • 493

java socket reading can't compare strings

Source Link
Asaf Nevo
  • 11.8k
  • 23
  • 85
  • 154

java socket reading can't compare strings

i'm written a code that reads a line from the socket.
if the line is "bye" i want it to output "nice". from some reason it doesn't work, although i did try to output the input with no conditions and it did says "bye"

this is my code

 String input = null; if (socket.getInputStream().available() > 0) input = in.readLine(); if (input != null) { input = input.trim(); if (input == "bye") out.println("nice"); out.println(input); }