I made this little function:
public String getDay() {
String day = (String)android.text.format.DateFormat.format("E", new java.util.Date());
return day;
}
I know that the android.text.format.DateFormat.form("E", new java.util.Date()); Returns a CharSequence, but is there any problem regarding casting this from a sequence of char’s?
I used the function like this:
String day = getDay();
if(day == "Tue") {
Toast.makeText(TaxiFaresActivity.this, day + " inside the if", Toast.LENGTH_LONG).show();
}
But it seems to me that I ever get into the function?
If I but the Toast outside, I get the following Toast
Tue
Which is right? Why doesn’t the program jumps right into the if-sentence?
In java == means you are comparing addresses not content so use equals when comparing objects: