Eclipse organize methods in alphabetical order

24,274

Solution 1

If you just want to view your class members in sorted order without modifying the code then you can click on the A/Z icon on the outline view, as others have pointed out. Alternatively, you may wish to sort the class members in the code itself, in which case you should right click your source or source file name to get the context sensitive menu, then select Source(Alt-Shift-S), Sort Members.

It will pop up a dialog box allowing you to customize the sort, choose your desired options and click ok.

Solution 2

You can actually sort members of your class in your code with eclipse, in my opinion this improves readability but should be used with caution.

select the class, Source > Sort Members

Thanks to marcggs' answer.

Solution 3

Press the Sort button in the Outline view. It has A, Z, and an arrow in it.

I wouldn't modify the Java source if I were you. If you're using an IDE such as Eclipse, then this adds no benefit, and there are a few costs, including:

  1. If the code already is checked in to source control, then resorting it can break the history
  2. I've never heard of a group with a coding convention of sorting methods alphabetically

Solution 4

You can use the alphabetic sort in the overview window for this.

alphabetic sort icon

Share:
24,274
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Author by

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

ADO.NET, MS SQL SERVER, Windows Forms Applications(VB and C#), Visual FoxPro, ASP.NET, WCF Web Services, Windows Mobile, and Android 2.2 & 3.0. When you sort all of Stackoverflow's members alphabetically, I am last. Check out my Android calculator. It can perform calculations in any numeral system from base 2 to base 36. It is free.Any Base Calculator Add me on google plus and I will add you into my developers circle.

Updated on December 23, 2020

Comments

  • zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz over 3 years

    I have a large class that contains about 30 methods. Is it possible to automatically sort them in alphabetical order in eclipse? I was hoping to do this so they would be easier to find when java browsing or looking at the class outline window.

  • leonbloy
    leonbloy almost 13 years
    This only changes how members are shown in the View, it does not modify the Java source
  • leonbloy
    leonbloy almost 13 years
    This only changes how members are shown in the View, it does not modify the Java source.
  • zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz almost 13 years
    You are correct leonbloy but that is enough for what I wanted.
  • jtoberon
    jtoberon almost 13 years
    I suppose that's true, but I don't think that physically re-sorting methods in your source code is a particularly good thing. I simply wouldn't do it.
  • Pieter De Bie
    Pieter De Bie over 9 years
    it would be nice if your code would be automatically organised like: constructors -> getA -> setA -> setB -> getB -> a...z