Telegram Group & Telegram Channel
👩‍💻 10 Java-однострочников — от вредных до полезных

Некоторые из этих однострочников — скорее ловушки: выглядят эффектно, но легко навредят в проде, другие — простые и надёжные, их можно использовать без сомнений.

Ниже — градация от “никогда так не делайте” до “можно и нужно применять”.

Поменять две переменные местами:
a = a + b - (b = a);


❗️ Получить случайный элемент:
list.get(new Random().nextInt(list.size()));


❗️ Прочитать все строки из файла:
Files.readAllLines(Path.of("file.txt"));


❗️ Проверить палиндром:
str.equals(new StringBuilder(str).reverse().toString());


Удалить null-значения:
list.removeIf(Objects::isNull);


Создать неизменяемый список:
List.of("Java", "Developer");


Найти максимум из двух чисел:
Math.max(a, b);


Объединить список в строку:
String.join(", ", fruits);


Посчитать совпадения:
list.stream().filter(x -> x > 10).count();


Отсортировать по убыванию:
list.sort(Comparator.reverseOrder());


Знаете ещё? Пишите в комментах 👇

tags: #обучение

📱 Java Developer | Чат
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/java_tg/3072
Create:
Last Update:

👩‍💻 10 Java-однострочников — от вредных до полезных

Некоторые из этих однострочников — скорее ловушки: выглядят эффектно, но легко навредят в проде, другие — простые и надёжные, их можно использовать без сомнений.

Ниже — градация от “никогда так не делайте” до “можно и нужно применять”.

Поменять две переменные местами:

a = a + b - (b = a);


❗️ Получить случайный элемент:
list.get(new Random().nextInt(list.size()));


❗️ Прочитать все строки из файла:
Files.readAllLines(Path.of("file.txt"));


❗️ Проверить палиндром:
str.equals(new StringBuilder(str).reverse().toString());


Удалить null-значения:
list.removeIf(Objects::isNull);


Создать неизменяемый список:
List.of("Java", "Developer");


Найти максимум из двух чисел:
Math.max(a, b);


Объединить список в строку:
String.join(", ", fruits);


Посчитать совпадения:
list.stream().filter(x -> x > 10).count();


Отсортировать по убыванию:
list.sort(Comparator.reverseOrder());


Знаете ещё? Пишите в комментах 👇

tags: #обучение

📱 Java Developer | Чат

BY Java Developer




Share with your friend now:
tg-me.com/java_tg/3072

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

The global forecast for the Asian markets is murky following recent volatility, with crude oil prices providing support in what has been an otherwise tough month. The European markets were down and the U.S. bourses were mixed and flat and the Asian markets figure to split the difference.The TSE finished modestly lower on Friday following losses from the financial shares and property stocks.For the day, the index sank 15.09 points or 0.49 percent to finish at 3,061.35 after trading between 3,057.84 and 3,089.78. Volume was 1.39 billion shares worth 1.30 billion Singapore dollars. There were 285 decliners and 184 gainers.

The Singapore stock market has alternated between positive and negative finishes through the last five trading days since the end of the two-day winning streak in which it had added more than a dozen points or 0.4 percent. The Straits Times Index now sits just above the 3,060-point plateau and it's likely to see a narrow trading range on Monday.

telegram from tr


Telegram Java Developer
FROM USA