strange output from ArrayList

<>

This question already has an answer here:

Answers


You need to override toString method. The Notizblock is a custom class, the default System.out will be classname@hashcode of the object, which is what you are seeing.

once you override the toString it will print the content of the object as per your toString implementation. Here is a sample:

@Override
public String toString() {
  return "Notizblock {" +
      "text='" + text + '\'' +
      ", datum='" + datum + '\'' +
      '}';
}

Yes. You can call the existing print method which you have defined.

System.out.println("alle notizen:");
for (Notizblock notiz :notizen ) {
    System.out.println(notiz.print());
}

The toString() is called automatically when you print (SOUT) anything. That is why overriding toString() will be a better approach then providing a custom method for doing the same job, unless you are doing some extra/special formatting of the data.


Need Your Help

How do I add a Fragment to an Activity with a programmatically created content view

android android-3.0-honeycomb android-fragments

I want to add a Fragment to an Activity that implements its layout programmatically. I looked over the Fragment documentation but there aren't many examples describing what I need. Here is the type...

How to Pass Details Model from Controller to View

c# asp.net asp.net-mvc wcf razor

I am accessing Data in Controller using a WCF Service.