title: How to dynamically populate the fields of a class in Java
body: <p>I know the following is not a good design but it's what I need to resolve</p>
  
  <pre><code>public final class TestBean {
  
      private String field1;
      private String field2;
      private String field3;
  
      public String getField1() {
          return field1;
      }
      public void setField1(String field1) {
          this.field1 = field1;
      }
      public String getField2() {
          return field2;
      }
      public void setField2(String field2) {
          this.field2 = field2;
      }
      public String getField3() {
          return field3;
      }
      public void setField3(String field3) {
          this.field3 = field3;
      }
  }
  </code></pre>
  
  <p>And the fields in the class need to be populated dynamically.</p>
  
  <p>Let say I have a array {"abc","def"}, and the class should initiated with field1="abc", field2="def" and field3=""; if the array is {"a"} and field1="a",field2="",field3="".</p>
  
  <p>Is it possible to achieve that?</p>
  
  <hr>
  
  <p>Updated: apparently I'm not stating the question well. In reality, the field is not just three, it's from field 1, field 2 to field 15. And then it's not just one field, there is another field call let say name, from name 1 to name 15:</p>
  
  <pre><code>public final class TestBean {
  
      private String field1;
      private String field2;
      ...
      private String field15;
  
      private String name1;
      private String name2;
      ...
      private String name15;
  
  }
  </code></pre>