I want to print a string only if it equals to a particular string e.g. "Hello", but when I run the program in a new thread, although it exe cutes the whole code, it does not print the string "Hello" even when the condition is true. I am attaching the code below :
new Thread(new Runnable() {
@Override
public void run() {
doGetRequest();
}
}).start();
private void doGetRequest() {
OkHttpClient client = new OkHttpClient();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(10,TimeUnit.MINUTES)
.writeTimeout(10, TimeUnit.MINUTES)
.readTimeout(10,TimeUnit.MINUTES);
String url = "my_url";
client = builder.build();
Request request = new Request.Builder().url(url).build();
try {
Response response = client.newCall(request).execute();
String jsonData = response.body().string();
JSONObject Jobject = new JSONObject(jsonData);
JSONArray jarray = Jobject.getJSONArray("Flights");
for(int i = 0; i<jarray.length();i++){
JSONObject object = jarray.getJSONObject(i);
Log.v("objectttt", String.valueOf(object));
String adft= object.getString("Adft");
if(adft=="Hello") {
Log.v("hereee", adft);
} else {
Log.v("hereee", adft);
//it prints Hello here
}
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}