title: How do I have a program create its own variables with Java?
body: <p>I would like to start off by saying that if this is common knowledge, please forgive me and have patience. I am somewhat new to Java.
  I am trying to write a program that will store many values of variables in a sort of buffer. I was wondering if there was a way to have the program "create" its own variables, and assign them to values.
  Here is an Example of what I am trying to avoid:</p>
  
  <pre><code>package test;
  
  import java.util.Scanner;
  
  public class Main {
       public static void main(String args[]) {
  
          int inputCacheNumber = 0;
          //Text File:
          String userInputCache1 = null;
          String userInputCache2 = null;
          String userInputCache3 = null;
          String userInputCache4 = null;
  
          //Program
          while (true) {
              Scanner scan = new Scanner(System.in);
              System.out.println("User Input: ");
              String userInput;
              userInput = scan.nextLine();
  
              // This would be in the text file
              if (inputCacheNumber == 0) {
                  userInputCache1 = userInput;
                  inputCacheNumber++;
                  System.out.println(userInputCache1);
              } else if (inputCacheNumber == 1) {
                  userInputCache2 = userInput;
                  inputCacheNumber++;
              } else if (inputCacheNumber == 2) {
                  userInputCache3 = userInput;
                  inputCacheNumber++;
              } else if (inputCacheNumber == 3) {
                  userInputCache4 = userInput;
                  inputCacheNumber++;
              }
              // And so on
  
          }
  
      }
  }
  </code></pre>
  
  <p>So just to try to summarize, I would like to know if there is a way for a program to set an unlimited number of user input values to String values. I am wondering if there is a way I can avoid predefining all the variables it may need.
  Thanks for reading, and your patience and help!
  ~Rane</p>