Q:

Java: Creating an array of random string numbers

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. 

A:

String[i] elementsToAdd2 = randomString(1000);
Is wrong.   String[i] is used to define an array like you have already did, here
String[] elementsToAdd2 = new String[30];

but you are trying to assign to it a value which is not array as it should be an array element.   So to add an element to an array, you use the array name and index and set it to the required value
elementsToAdd2[i] = randomString(1000);

Additionally
Array Size
This code will cause an ArrayOutOfBoundsIndexException as you are trying to access elements in the array that are one greater than it's length with
i <= elementsToAdd2.length

As an arrays length is equal to how many locations it has but these location indexes start at 0, meaning the last element is always length-1, use
i < elementsToAdd2.length

Method Access (pointed out by @Dominic)
The method you are accessing randomString() from is static (as it's your main method) but that method is an instance variable (is associated with an object), you need to access it via the object it belongs to i.e.theFunc, like so
 theFunc.randomString(1000)

