Adding to ArrayList in Java
<p>I am new in Java development and I tried this program:</p>

<pre><code>    List&lt;String&gt; myList = new ArrayList&lt;String&gt;();
    for(int i = 0;i&lt;ProductNumber;i++)
    {
       myList.add( mProducts[i].Name);
    }
    mProducts[1].Name = "Hello";
</code></pre>

<p>When I made <code>println</code> to show <strong>myList</strong> content:  </p>

<p><strong>Expected</strong> </p>

<blockquote>
  <p>"A"<br>
  "B"<br>
  "C"  </p>
</blockquote>

<p><strong>Current</strong>  </p>

<pre><code>&gt;"A"  
&gt;"Hello"  
&gt;"C"  
</code></pre>

<p>Can anybody tell me what is going on?</p>

<p>This is the code that I made:</p>

<pre><code>    public class xmlParsing 
    {   
    private final static String XML_FILE_NAME = "Configuration.xml";
    private final static String PRODUCT_NODE = "product";
    private final static String TASK_NODE = "task";
    private final static String NAME_ITEM = "name";
    private final static String DURATION_ITEM = "duration";
    private final static String RATE_ITEM = "rate";

    private static int ProductNumber = 0;
    private static int TaskNumber = 0;
    private static Product mProducts[] = new Product[Product.MAX_PRODUCT_NUMBER];

    public xmlParsing()
    {
    }

    public void parseXML ()
    {
        Product[] Products = new Product[Product.MAX_PRODUCT_NUMBER];
        try 
        {
            File xmlFile = new File(XML_FILE_NAME);
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);
            doc.getDocumentElement().normalize();
            NodeList productsNode = doc.getElementsByTagName(PRODUCT_NODE);
            ProductNumber = productsNode.getLength();
            Product mproduct = new Product();
            Task mtask = new Task();
            for (int i = 0; i &lt; productsNode.getLength(); i++) 
            {
                Node productNode = productsNode.item(i);
                if (productNode.getNodeType() == Node.ELEMENT_NODE) 
                {
                    Element element1 = (Element) productNode;
                    mproduct.Name = getValue(NAME_ITEM, element1);
                    NodeList tasksNode = element1.getElementsByTagName(TASK_NODE);
                    TaskNumber = tasksNode.getLength();
                    Task[] Tasks = new Task[Task.MAX_TASKS_NUMBER];
                    for (int j = 0; j &lt; tasksNode.getLength(); j++) 
                    {
                        Node taskNode = tasksNode.item(j);
                        if (taskNode.getNodeType() == Node.ELEMENT_NODE) 
                        {
                            Element element2 = (Element) taskNode;
                            mtask.Name = getValue(NAME_ITEM, element2);
                    mtask.Duration = Double.parseDouble(getValue(DURATION_ITEM, element2));
                            mtask.Rate = Double.parseDouble(getValue(RATE_ITEM, element2));
                            Tasks[j] = new Task(mtask);
                        } 
                    }
                    mproduct.Tasks = Tasks;
                    Products[i] = new Product(mproduct);
                }
            }
        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }
        mProducts = Products;
    }

    private static String getValue(String tag, Element element) 
    {
        NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
        Node node = (Node) nodes.item(0);
        return node.getNodeValue();
    }

    public static List&lt;String&gt; getProdcutNames() 
    {
       String ps[] = new String[ProductNumber];
       List&lt;String&gt; myList = new ArrayList&lt;String&gt;();
       for(int i = 0;i&lt;ProductNumber;i++)
       {
           ps[i] =  mProducts[i].Name;
           myList.add(new String(mProducts[i].Name));
       }
        mProducts[2].Name = "Hello";
       return myList;
    }

    public int getProductNumber()
    {
        return ProductNumber;
    }

    public int getTasktNumber()
    {
        return TaskNumber;
    }
    }

    public class Task {
    public static final int MAX_TASKS_NUMBER = 100;
    public String Name;
    public double Duration;
    public double Rate;

    public Task(){
        Name = "";
        Duration = 0;
        Rate = 0;
    }

    public Task(Task t){
        Name = t.Name;
        Duration = t.Duration;
        Rate = t.Rate;
    }

    }

    public class Product {
    public static final int MAX_PRODUCT_NUMBER = 200;
    public String Name;
    public Task[] Tasks;

    public Product(){
        Name = "";
        Tasks = null;
    }

    public Product(Product p){
        Name = p.Name;
        Tasks = p.Tasks;
    } 
    }


    public class Production {

    public static void main(String[] args) {
        xmlParsing parser = new xmlParsing();
        parser.parseXML();
        for(int i=0;i&lt;parser.getProductNumber();i++)
            System.out.println(parser.getProdcutNames().get(i));

    }
    }
</code></pre>

<p>The xml file is </p>

<pre><code>    &lt;product&gt;
    &lt;name&gt;1510&lt;/name&gt;
    &lt;task&gt;
        &lt;name&gt;DECOUPAGE PRESSE 250T&lt;/name&gt;
        &lt;duration&gt;1&lt;/duration&gt;
        &lt;rate&gt;144&lt;/rate&gt;
    &lt;/task&gt;
    &lt;task&gt;
        &lt;name&gt;LAMINAGE PARBOLIQUE 1&lt;/name&gt;
        &lt;duration&gt;0&lt;/duration&gt;
        &lt;rate&gt;72.1&lt;/rate&gt;
    &lt;/task&gt;
     &lt;/product&gt;
    &lt;product&gt;
    &lt;name&gt;2020&lt;/name&gt;
    &lt;task&gt;
        &lt;name&gt;DECOUPAGE PRESSE 250T&lt;/name&gt;
        &lt;duration&gt;1&lt;/duration&gt;
        &lt;rate&gt;144&lt;/rate&gt;
    &lt;/task&gt;
    &lt;task&gt;
        &lt;name&gt;LAMINAGE PARBOLIQUE 1&lt;/name&gt;
        &lt;duration&gt;0&lt;/duration&gt;
        &lt;rate&gt;72.1&lt;/rate&gt;
    &lt;/task&gt;
     &lt;/product&gt;
</code></pre>

<p>Expected : 1510  2020
Current    1510 Hello</p>
