0

I am trying to implement sorting of an arraylist. My code so far is:

public String getResult() {
    String ret;
    Iterator<denn> i = collection.iterator();
    while (i.hasNext()) {
        Denn d = (Denn) i.next();
        ret = d.toString();
    }
    return ret;

After I run it, what I get seems to be some kind of pointer to memory. ie.e package.Denn@6996db8

What am I doing wrong?

sayid jetzenden
  • 153
  • 1
  • 11
  • Have you written a method called `toString` inside the `Denn` class, to specify how a `Denn` object should appear as a `String`? – Dawood ibn Kareem Jul 22 '16 at 22:32
  • That is not a memory pointer, but a hash code. It is the default implementation of the `toString()` method. If you want your `Denn` class to provide a better description, just implement the `toString()` method. – Andreas Jul 22 '16 at 22:33
  • @And Can you provide me with more information about how to write that method? Should it be something with annotation (@Override)?? – sayid jetzenden Jul 22 '16 at 22:36
  • @sayidjetzenden Why don't you just follow the duplicate link and read the answers there? – Andreas Jul 22 '16 at 22:37
  • @Andreas thanks, didn't notice that. – sayid jetzenden Jul 22 '16 at 22:39

1 Answers1

0

I don't think your problem is an iterator problem, but rather that you might not be implementing a custom toString() on Denn. The default behavior is to print the object hashcode

See: https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()

Uri
  • 88,451
  • 51
  • 221
  • 321