Java8 | 42 | Integer Overflow/underflow Issue while using Comparator

preview_player
Показать описание
In the previous video, we learned how to sort with the help of a comparator interface. When using a comparator interface we will usually use the arithmetic operator for its implementation. This is fine for most of the cases, however, in some edge cases, it's not recommended, especially when we are dealing with Integer's max or min value. In these scenarios, we will encounter an integer overflow issue and we will not get the desired output.

*️⃣What is an example of integer overflow/underflow?
When you go above the maximum value of the signed integer, the result usually becomes a negative number. For example, 2,147,483,647 +1 is usually −2,147,483,648. When you go below the minimum value (underflow), the result usually becomes a positive number. For example, −2,147,483,648 − 1 is usually 2,147,483,647.
*️⃣How can we avoid this integer overflow/underflow while using a comparator?

Support by donating:
---------------------------------
Name: Arulprasath

Instagram: im_arulprasath

You can watch my other tutorials
------------------------------------------------------

Рекомендации по теме
join shbcf.ru