Telegram Group & Telegram Channel
Парадокс Comparator’а

Если вам нужно написать Comparator для сортировки объектов по возрастанию, обычно он выглядит так:

public class ByScoreComparator implements Comparator<User> {

@Override
public int compare(User u1, User u2) {
return (int) signum(u2.getAge() - u1.getAge());
}
}


➡️ Главная проблема — понять, от чего отнимать, чтобы порядок был правильным. Правильный ответ с первого раза получается редко, и часто мы замечаем ошибку уже после запуска кода.

Теперь это не нужно. Можно использовать ссылки на методы:

Comparator<User> comparator = Comparator
.comparingDouble(User::getAge)
.thenComparing(User::getName);
List<User> hList = ...;
hList.sort(comparator);


🗣 Такой подход упрощает создание компараторов.



tg-me.com/javarocks/265
Create:
Last Update:

Парадокс Comparator’а

Если вам нужно написать Comparator для сортировки объектов по возрастанию, обычно он выглядит так:

public class ByScoreComparator implements Comparator<User> {

@Override
public int compare(User u1, User u2) {
return (int) signum(u2.getAge() - u1.getAge());
}
}


➡️ Главная проблема — понять, от чего отнимать, чтобы порядок был правильным. Правильный ответ с первого раза получается редко, и часто мы замечаем ошибку уже после запуска кода.

Теперь это не нужно. Можно использовать ссылки на методы:

Comparator<User> comparator = Comparator
.comparingDouble(User::getAge)
.thenComparing(User::getName);
List<User> hList = ...;
hList.sort(comparator);


🗣 Такой подход упрощает создание компараторов.

BY JavaRocks


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/javarocks/265

View MORE
Open in Telegram


JavaRocks Telegram | DID YOU KNOW?

Date: |

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

Newly uncovered hack campaign in Telegram

The campaign, which security firm Check Point has named Rampant Kitten, comprises two main components, one for Windows and the other for Android. Rampant Kitten’s objective is to steal Telegram messages, passwords, and two-factor authentication codes sent by SMS and then also take screenshots and record sounds within earshot of an infected phone, the researchers said in a post published on Friday.

JavaRocks from in


Telegram JavaRocks
FROM USA