我在应用程序的内存数据库中使用Redis。我们使用sAdd方法向集合中添加一些字符串值,并使用smembers方法从集合中获取值。此方法返回Set List<String> list = Arrays.asList((servKeys)).toArray();
最佳答案
您可以将Base64
编码器与Stream API结合使用:
List<String> list = servKeys.stream()
.map(bytes -> Base64.getEncoder().encodeToString(bytes))
.collect(Collectors.toList());
除了Base64
之外,您还可以使用new String(bytes, StandardCharsets.UTF_8)
。这取决于
byte[]
是哪种数据。上面的代码假定使用纯文本,但是,您可以轻松调整行为。
关于java - 将Set <byte []>转换为List <String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64459869/