gpt4 book ai didi

java - 奇怪的 Apache Commons Lang StringUtils.join 结果

转载 作者:太空宇宙 更新时间:2023-11-04 07:10:22 24 4
gpt4 key购买 nike

我从 Apache Commons Lang 的 StringUtils.join 得到了奇怪的结果。假设我有:

List<String> values = new LinkedList<>();

values.add("120");
values.add("123456789");
values.add("9000");
values.add("en");

byte[] data = StringUtils.join(values, new char[] {1}).getBytes();

我期望有 31323001313233343536373839013930303001656e ,即 120.123456789.9000.en ,其中 .0x01 。但令我困惑的是我得到了 相反,5b3132302c203132333435363738392c20393030302c20656e5d5b4340333664303437 会转换为 [120, 123456789, 9000, en][C@36d047 。我这样做的方式是否存在导致奇怪值的问题?

最佳答案

您正在使用以下方法:

public static <T> String join(T... elements)

Joins the elements of the provided array into a single String containing the provided list of elements.

No separator is added to the joined String. Null objects or empty strings within the array are represented by empty strings.

因此,此方法在字符串列表和 char 数组上调用 toString(),并连接结果。

您想要传递字符或字符串分隔符作为第二个参数:

StringUtils.join(values, '.').getBytes();

关于java - 奇怪的 Apache Commons Lang StringUtils.join 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20748351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com