forked from javaevolved/javaevolved.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhex-format.json
More file actions
50 lines (50 loc) · 1.71 KB
/
Copy pathhex-format.json
File metadata and controls
50 lines (50 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
"id": 75,
"slug": "hex-format",
"title": "HexFormat",
"category": "datetime",
"difficulty": "intermediate",
"jdkVersion": "17",
"oldLabel": "Java 8",
"modernLabel": "Java 17+",
"oldApproach": "Manual Hex Conversion",
"modernApproach": "HexFormat",
"oldCode": "// Pad to 2 digits, uppercase\nString hex = String.format(\n \"%02X\", byteValue);\n// Parse hex string\nint val = Integer.parseInt(\n \"FF\", 16);",
"modernCode": "HexFormat hex = HexFormat.of()\n .withUpperCase();\nString s = hex.toHexDigits(\n byteValue);\nbyte[] bytes =\n hex.parseHex(\"48656C6C6F\");",
"summary": "Convert between hex strings and byte arrays with HexFormat.",
"explanation": "HexFormat provides bidirectional hex encoding/decoding for bytes, ints, and arrays. Configure delimiters, prefix, suffix, and case. No more manual formatting or parsing.",
"whyModernWins": [
{
"icon": "📐",
"title": "Bidirectional",
"desc": "Convert bytes→hex and hex→bytes with one API."
},
{
"icon": "🔧",
"title": "Configurable",
"desc": "Delimiters, prefix, suffix, upper/lower case."
},
{
"icon": "📦",
"title": "Array support",
"desc": "Encode/decode entire byte arrays at once."
}
],
"support": {
"state": "available",
"description": "Widely available since JDK 17 LTS (Sept 2021)"
},
"prev": "datetime/math-clamp",
"next": "security/pem-encoding",
"related": [
"datetime/date-formatting",
"datetime/instant-precision",
"datetime/duration-and-period"
],
"docs": [
{
"title": "HexFormat",
"href": "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/HexFormat.html"
}
]
}