title: Create an Arraylist of classes
body: <p>I have an Arraylist  list1 (banana,orange...) , and i have a class fruit .
  i want to creat an  Arraylist  list2 which its elements are instances of fruit and the names of instances are the elements of list1 . i did all intences with same name but i need a specific name fo each instance . is that possible in java ?
  i tried this but it doesn't worked for me</p>
  
  <pre><code>public class list {
     public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
         ArrayList&lt;String&gt; list1=new ArrayList&lt;&gt;();
         ArrayList&lt;Fruit&gt; list2=new ArrayList&lt;&gt;();
         list1.add("banana");
         list1.add("Orange");
         list1.add("strawberry");
         for (int i = 0; i &lt; list1.size(); i++) {
            String className=list1.get(i);
             Class&lt;?&gt; clazz = Class.forName(className);
             Object obj = clazz.newInstance();
             list2.add((Fruit) obj);
         }
     }
  }
  
  
  public class Fruit {
      int price;
      String color;
  
      public Fruit() {
      }
  
      public int getPrice() {
          return price;
      }
  
      public String getColor() {
          return color;
      }
  
      public void setPrice(int price) {
          this.price = price;
      }
  
      public void setColor(String color) {
          this.color = color;
      }
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/sB1PI.png" alt="enter image description here"></p>