I have a set of code that, currently, uses a pre-set list of 30 manually inputed strings made up of numbers, which can be seen below:
String[] elementsToAdd2 = { "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" };
I want to replace this with something else that can produce any amount of random string numbers that I want, between a certain pre-set size. What I had in mind was to use the following code in its place:
public class HashFunction {
.
.
.
private Random r = new Random();
public String randomString(int limit)
{
int n = r.nextInt(limit);
return n+"";
}
.
.
.
public static void main(String[] args) {
HashFunction theFunc = new HashFunction(30); // this is where you can control the number of spaces in the hash table!!!
String[] elementsToAdd2 = new String[30];
for (int i = 0; i <= elementsToAdd2.length; i++)
{
String[i] elementsToAdd2 = randomString(1000);
}
When I read this, I take it to mean that the array string value at "i" will be assigned to the random value that will be between 0 and 1000. However, I instead get an error message. It says that a ";" was expected, and that I have incompatible types. I think that Java is reading this as saying that I am trying to set an array of strings equal to single string, even though I included the "i" within "String[i]" to specify where in the array to place the value.
If anyone can help me understand my problem, please let me know. Thank you!
p.s. This code creates hash tables, in case that is relevant to the problem I am encountering. I can provide the code if you'd like, but I wanted to isolate the problem and only show what is relevant to it.
String[i] elementsToAdd2 = ...butelementsToAdd2[i] = .... And the loop should not run whilei <= elementsToAdd2.length, but whilei < elementsToAdd2.length.