gpt4 book ai didi

java - 数组值转字符串函数

转载 作者:行者123 更新时间:2023-11-30 10:54:38 26 4
gpt4 key购买 nike

所以基本上我需要制作一个哈希表,我知道如何用字符串数组来做,但我需要用我做的随机数组来做。

基本上这是另一个用户给我的随机数代码

    int[] array = new int[8000];
Random rng = new Random();
for (int i = 0; i < 8000; i++) {
array[i] = rng.nextInt(65536);
}

我需要它以某种方式在我教授的示例代码中变成这样的东西

String[] array = { "100", "510", "170", "214", "268", "398",
"235", "802", "900", "723", "699", "1", "16", "999", "890",
"725", "998", "978", "988", "990", "989", "984", "320", "321",
"400", "415", "450", "50", "660", "624" };

我尝试并这样做了:

 int[] array = new int[8000];
Random rng = new Random();
for (int i = 0; i < 8000; i++) {
array[i] = rng.nextInt(65536);
String strI = Integer.toString(i);
String[] array = {i + "," };

最佳答案

您可以将其设为 String[] 并填充它(我更喜欢使用 array.length,而不是再次硬编码 8000)。类似的东西,

String[] array = new String[8000];
Random rng = new Random();
for (int i = 0; i < array.length; i++) {
array[i] = String.valueOf(rng.nextInt(65536));
}

关于java - 数组值转字符串函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33590550/

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