0
public class networking2{

public static void main(String []args) throws IOException{
    String urlLink = "http://rocktheparty5231.xtgem.com/out";
    URL url = new URL(urlLink);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line;
    while((line = in.readLine()) != null) {sb.append(line);}
    in.close();

    // problem is here
    System.out.println(sb.toString()); // sb is returning output "uc"
    System.out.println(sb.toString()=="uc"); // how is this boolean false
    // i am not able to do any boolean operation with this correctly please help

}

}

http functions are working perfectly but the boolean is not working as it should work

screenshot of eclipse

PowerStat
  • 3,757
  • 8
  • 32
  • 57
Amir Rahman
  • 1,076
  • 1
  • 6
  • 15
  • Required reading for you: ['==' vs 'equals()'](https://stackoverflow.com/questions/7520432/what-is-the-difference-between-and-equals-in-java#7520464). In short, == checks in-memory reference, equals() (generally) checks value. – Austin Schaefer Jun 14 '19 at 09:21
  • thank you for the knowledge now i understand why it was false – Amir Rahman Jun 16 '19 at 09:19

1 Answers1

3

In Java, when comparing string, use .equals. Please have a try like this.

System.out.println(sb.toString().equals("uc"));

You can read more here

Soe Thiha
  • 521
  • 1
  • 5
  • 6