22.what is the difference between a.equals(b) and a == b




















The main difference between the. If a class does not override the equals method , then by default it uses the equals Object o method of the closest parent class that has overridden this method. Both s1 and s2 refer to different objects. Java String Pool. We can also apply equality operators for object types. Otherwise, we will get compile-time error. If all the contents of both the strings are same then it returns true. If all characters are not matched then it returns false.

In the above example, we are creating 3 Thread objects and 2 String objects. Both the objects contain the same String i. This article is contributed by Veturi Lakshmi Prathyusha. Note that plugging numbers into expressions may not be conclusive. It is conclusive, however, if you get different results after plugging in different numbers: the conclusion is that the relationship cannot be determined from the information given. It is also conclusive if there are only a small number of possible numbers to plug in and all of them yield the same result, say, that Quantity B is greater.

Now suppose there are an infinite number of possible numbers to plug in. If you plug many of them in and each time the result is, for example, that Quantity A is greater, you still cannot conclude that Quantity A is greater for every possible number that could be plugged in. Further analysis would be necessary and should focus on whether Quantity A is greater for all possible numbers or whether there are numbers for which Quantity A is not greater. Step 1: Multiply both sides by 5 to get.

Step 2: Subtract 3 y from both sides to get. Step 3: Divide both sides by 2 to get. The comparison is now simplified as much as possible. In order to compare 1 and y , note that you are given the information above Quantities A and B. However, the problem asks for a comparison between Quantity A and Quantity B, not a comparison between 1 and y. To go from the comparison between 1 and y to a comparison between Quantities A and B, start with the last comparison, and carefully consider each simplification step in reverse order to determine what each comparison implies about the preceding comparison, all the way back to the comparison between Quantities A and B if possible.

Since step 3 was " divide both sides by 2," multiplying both sides of the comparison by 2 implies the preceding comparison thus reversing step 3. Each simplification step can be reversed as follows:. Thus the correct answer is Choice B , Quantity B is greater. While some simplification steps like subtracting 3 from both sides or dividing both sides by 10 are always reversible, it is important to note that some steps, like squaring both sides, may not be reversible.

Also, note that when you simplify an inequality , the steps of multiplying or dividing both sides by a negative number change the direction of the inequality; for example, if then So the relationship in the final, simplified inequality may be the opposite of the relationship between Quantities A and B.

This is another reason to consider the impact of each step carefully. Step 1: Multiply both sides by 2 to get. Step 2: Add to both sides to get. Step 3: Simplify the right-hand side using the fact that to get. In reverse order, each simplification step implies equal to in the preceding comparison. Outside of his full time role as a Principal Technologist, Aaron is a serial side project starter, the latest of which is a Spring Boot Java web app that manages contact info.

Your email address will not be published. Save my name, email, and website in this browser for the next time I comment. Nov 7, Comparable , Comparator , Equals , groovy , Java. Aaron Burk. In Groovy, it is calling equals. It is strongly recommended, but not strictly required that x. November 8, at pm. Leave a Reply Cancel reply Your email address will not be published.



0コメント

  • 1000 / 1000