I'm new at Java and I came across a problem I couldn't find a solution to, so maybe somebody can help me out. When I write this code:
ArrayList<String> Liste = new ArrayList<>(); String Name; Liste.add("Harry"); Name = Liste.get(0); Name = "Dieter"; System.out.print(Liste.get(0)); System.out.print(Name); The output is, as expected:
Harry Dieter However, if I change the type to a custom object:
ArrayList<Names_Class> Liste = new ArrayList<>(); Names_Class Name; Liste.add(new Names_Class()); Liste.get(0).First_Name = "Harry"; Name = Liste.get(0); Name.First_Name = "Dieter"; System.out.print(Liste.get(0)); System.out.print(Name); The output becomes:
Dieter Dieter So it seems Java only copies a references or something. Could somebody explain what happens here, and how I can get a complete copy of a single item out of an ArrayList?

ListeandName) are known as reference variables.listeandname.