title: Duplicate first index of array in java application
body: <p>I am creating a little utility program. In this program I am trying to assign an array to a Java Object like so: 
  <code>new Food( name, state, arrayOfSymptoms, comment, isCategory)</code>, where arrayOfSymptoms is the array I have problems with.</p>
  
  <p>When I send the content of the array to output log,  <code>[sym1, sym2, sym3, sym4]</code>.<br>
  However, after the construction is finished the array looks like this: <code>[sym1, sym1, sym2, sym3, sym4]</code>  </p>
  
  <p>Does someone know an easy way to fix this problem, or do I have to create a lot of extra code to delete and move indexes?</p>
  
  <p>Thank you in advance!</p>
  
  <p>Edit:</p>
  
  <p>Code before constructor:   </p>
  
  <pre><code>        Symptoms[] allSyms = new Symptoms[selSyms.size()];
          for (int j = 0; j &lt; selSyms.size(); j++) {
              allSyms[j] = selSyms.get(j);
              System.out.println("CurrSym(" + j + "): " + allSyms[j]);
          }
  
          System.out.println("Amount of symptoms selected: " + allSyms.length);
  
          if(        // Basic Form Validation
                  !nameField.getText().isEmpty()) {
  
              if (!isCategory.isSelected())
                  MainController.makeLeaf(
                          MainController.categoryTitles.indexOf(categories.getValue()),
                          new Food(
                                  nameField.getText(),
                                  stateChoice.getSelectionModel().getSelectedIndex(),
                                  allSyms, // Symptoms Here
                                  "",
                                  false)
                  );
          }
  </code></pre>
  
  <p>Creates the output shown here:   </p>
  
  <p>CurrSym(0): Name: Sym1, Comment: "" </p>
  
  <p>CurrSym(1): Name: Sym2, Comment: ""</p>
  
  <p>CurrSym(2): Name: Sym3, Comment: ""</p>
  
  <p>CurrSym(3): Name: Sym4, Comment: ""</p>
  
  <p>This clearly shows that the array only contains 4 elements.
  However, when I convert the object into JSON, the output becomes as shown: 
  <code>{"title": "Test Food", "state": 0, "symptoms":[{"name":"Sym1","comment":""},{"name":"Sym1","comment":""},{"name":"Sym2","comment":""},{"name":"Sym3","comment":""},{"name":"Sym4","comment":""}],"comment": "", "isCategory": false}</code></p>
  
  <p>The code to convert the object to JSON looks like this:   </p>
  
  <pre><code>public String symptomsToJSON()
  {
      String allSymptoms = "";
  
      if(getSymptoms() != null)
      {
          for (int i = 0; i &lt; symptoms.length; i++) {
              if (i == 0)
                  allSymptoms += symptoms[i].toJSON();
              allSymptoms += "," + symptoms[i].toJSON();
          }
      }
  
      return allSymptoms;
  }
  
  public String toJSON()
  {
      return "{\"title\": \"" + title + "\", \"state\": "+ state + ", \"symptoms\":[" + symptomsToJSON() + "],\"comment\": \"" + comment +"\", \"isCategory\": " + isCategory + "}";
  }
  </code></pre>
  
  <p>Hope this new information helps!</p>