This is my output
{
   { d:  { a e } }
   { e:  { b c d } }
   { b:  { a e } }
   { c:  { a e } }
   { a:  { b c d } }
}

I used this to_string to print this output
    public final String toString() {
            StringBuffer sb = new StringBuffer();

            sb.append("{\n");
            for (Iterator i = vertices_.values().iterator(); i.hasNext();)
                sb.append("   " + i.next() + "\n");
            sb.append("}");
            // Arrays.sort(sb);
            return sb.toString();
        }
        I want these in sorted order.
        How should I do it?

Recommended Answers

All 2 Replies

run a sorting method on it.
you can implement your own sorting algorithm and use that.

The Arrays class has methods for sorting arrays.
If you don't want to mess up your data you'll need to create a copy of the array, sort that, then convert it to a String

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.