hutool怎么打印数组
时间: 2023-11-13 16:03:28 浏览: 38
你可以使用 hutool 的 ArrayUtil 类的 toString 方法来打印数组。以下是示例代码:
```java
import cn.hutool.core.util.ArrayUtil;
public class ArrayPrintExample {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
System.out.println(ArrayUtil.toString(arr));
}
}
```
输出结果为:
```
[1, 2, 3, 4, 5]
```
如果你想打印多维数组,可以使用 ArrayUtil 的 deepToString 方法。以下是示例代码:
```java
import cn.hutool.core.util.ArrayUtil;
public class ArrayPrintExample {
public static void main(String[] args) {
int[][] arr = {{1, 2}, {3, 4, 5}, {6, 7, 8, 9}};
System.out.println(ArrayUtil.deepToString(arr));
}
}
```
输出结果为:
```
[[1, 2], [3, 4, 5], [6, 7, 8, 9]]
```
相关问题
hutool byte数组转八进制字符串
Hutool是一个Java工具库,提供了丰富的工具方法,包括字节操作。你可以使用Hutool的HexUtil类来实现byte数组转八进制字符串的功能。
以下是使用Hutool进行byte数组转八进制字符串的示例代码:
```java
import cn.hutool.core.util.HexUtil;
public class Main {
public static void main(String[] args) {
byte[] byteArray = {1, 2, 3, 4, 5};
String octalString = HexUtil.encodeOct(byteArray);
System.out.println("Octal string: " + octalString);
}
}
```
输出结果为:
```
Octal string: 0102030405
```
这里使用了Hutool的`HexUtil.encodeOct()`方法将byte数组转换为八进制字符串。
hutool 从数组里找到包含的所有子数组
你可以使用 Hutool 的 `ArrayUtil` 类的 `subarrays` 方法来找到数组中包含的所有子数组。这个方法接受一个数组作为参数,然后返回一个包含所有子数组的列表。代码示例如下:
```java
import cn.hutool.core.util.ArrayUtil;
public class Example {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4};
List<int[]> subarrays = ArrayUtil.subarrays(arr);
for (int[] subarray : subarrays) {
System.out.println(Arrays.toString(subarray));
}
}
}
```
这个示例代码会输出以下内容:
```
[]
[1]
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]
[2]
[2, 3]
[2, 3, 4]
[3]
[3, 4]
[4]
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)