Can we use relational operators with strings?
Share
Talk Programming , Career, Mental Health, Talk Personal Finance ❤️ Post a query and receive responses ✅
Post a query and receive responses. Ask anything, Ask Mitra ❤️
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When comparing two or more strings we can use relational operators with string for simple demo here is simple program to comparing two strings
yes you can also compare strings using relational operators. When a relational operator is used with strings, the integer value of each character of the left operand is compared to the integer value of each character of the right operand working from left to right.
example.
“tim” == “tom” // false because the 2nd characters i and o do not match
“Tim” == “tim” // false because T and t do not match
“abc” < “abd” // true because for 3rd character, the integer value of c is less than the integer value of d
hope this helps
Yes, we can use it to compare strings There is no problem to use them until and unless you required them. For instance, string1.equals(string2) in Java we can use this to check if they have the same value or not using the relative operator.
We can but the question is why would we?