Q:

How to display a contents from an Array List in a string?

I am a beginner at using java and I do not know how to get the system to output the contents from my array list in a string
private void createRooms()
{
    Room townCenter, boots, tesco, library, home;

    // create the rooms
    townCenter = new Room("in the town center", contents);
    boots = new Room("in boots drug store", contents);
    tesco = new Room("in tesco's", contents);
    library = new Room("in the city library", contents);
    home = new Room("at home", contents);

note where it says 'contents' I am trying to display the items in said room.
this is where I have started my Array List
milk = new Objects("milk");
paracetamol = new Objects("paracetamol");
book = new Objects("book");
money = new Objects("money");

tesco.addObjects(milk);
boots.addObjects(paracetamol);
library.addObjects(book);
home.addObjects(money);

the Array List itself is in a different class and looks like this
public ArrayList<Objects> contents;

So what I am trying to do is have the system print out the contents of each room. Any help is welcome and appreciated :)

A:

First you should Override the toString() of your "Objects" which represent the contents of your rooms. This way you can give a friendly description to each "Objects".
Inside of your Objects class:
@Override
public String toString() 
{ 
    return "Object: " + objectName; //use whatever variable you store "Milk" or its name in
} 

Then, you can Override your Room class's toString() method in order to provide your description of the room, which in your case you want to do by printing out all of the items in your "contents" ArrayList. 
You can do this by doing the following in your Room class:
@Override
public String toString() 
{ 
    return "Contents in the room" + contents.toString();
} 

An ArrayList has a toString method which will call the toString() method for each element in the list. Each element in our case is an "Objects" which we just overrode the toString() method for to print out exactly what we wanted. 
Now when you call:
System.out.println(tesco)

It will output:
 Contents in the room:
 Object: Milk

