JAVA_IIBRARY Telegram 1388
JDK 22 представил класс java.text.ListFormat. Используйте его, когда нужно отформатировать список строк в удобочитаемый вид. Например, вот такая программа:

final List<String> days = List.of("Mon", "Wed", "Fri");

void main() {
print(Type.STANDARD);
print(Type.OR);
print(Type.UNIT);
}

private void print(Type type) {
print(type, Style.FULL);
print(type, Style.SHORT);
print(type, Style.NARROW);
}

private void print(Type type, Style style) {
var format = ListFormat.getInstance(Locale.US, type, style);
var result = format.format(days);
System.out.printf("%-8s + %-7s: %s%n", type, style, result);
}


Вывод:

STANDARD + FULL   : Mon, Wed, and Fri
STANDARD + SHORT : Mon, Wed, & Fri
STANDARD + NARROW : Mon, Wed, Fri
OR + FULL : Mon, Wed, or Fri
OR + SHORT : Mon, Wed, or Fri
OR + NARROW : Mon, Wed, or Fri
UNIT + FULL : Mon, Wed, Fri
UNIT + SHORT : Mon, Wed, Fri
UNIT + NARROW : Mon Wed Fri


Также можно использовать ListFormat для разбора отформатированной строки обратно в список

Ставь лайк если полезно 🪑

👉 Java Portal
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/Java_Iibrary/1388
Create:
Last Update:

JDK 22 представил класс java.text.ListFormat. Используйте его, когда нужно отформатировать список строк в удобочитаемый вид. Например, вот такая программа:

final List<String> days = List.of("Mon", "Wed", "Fri");

void main() {
print(Type.STANDARD);
print(Type.OR);
print(Type.UNIT);
}

private void print(Type type) {
print(type, Style.FULL);
print(type, Style.SHORT);
print(type, Style.NARROW);
}

private void print(Type type, Style style) {
var format = ListFormat.getInstance(Locale.US, type, style);
var result = format.format(days);
System.out.printf("%-8s + %-7s: %s%n", type, style, result);
}


Вывод:

STANDARD + FULL   : Mon, Wed, and Fri
STANDARD + SHORT : Mon, Wed, & Fri
STANDARD + NARROW : Mon, Wed, Fri
OR + FULL : Mon, Wed, or Fri
OR + SHORT : Mon, Wed, or Fri
OR + NARROW : Mon, Wed, or Fri
UNIT + FULL : Mon, Wed, Fri
UNIT + SHORT : Mon, Wed, Fri
UNIT + NARROW : Mon Wed Fri


Также можно использовать ListFormat для разбора отформатированной строки обратно в список

Ставь лайк если полезно 🪑

👉 Java Portal

BY Java Portal | Программирование


Share with your friend now:
tgoop.com/Java_Iibrary/1388

View MORE
Open in Telegram


Telegram News

Date: |

In handing down the sentence yesterday, deputy judge Peter Hui Shiu-keung of the district court said that even if Ng did not post the messages, he cannot shirk responsibility as the owner and administrator of such a big group for allowing these messages that incite illegal behaviors to exist. Telegram Android app: Open the chats list, click the menu icon and select “New Channel.” But a Telegram statement also said: "Any requests related to political censorship or limiting human rights such as the rights to free speech or assembly are not and will not be considered." Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. Channel login must contain 5-32 characters
from us


Telegram Java Portal | Программирование
FROM American