Java Beginner
Java Beginner

Reputation: 1655

How to indent java code assignment of variables in eclipse

I have this code which I want to indent:

int[] myArray =
    { 1, 2, 3, 4, 5, 6 };
    int theInt = 1;
    String someString = "Hello";
    double aDouble = 3.0;

I want the above code to be column indented, like this:

int[]  myArray    = { 1, 2, 3, 4, 5, 6 };
int    theInt     = 1;
String someString = "Hello";
double aDouble    = 3.0;

I have tried different options in: Windows > Preferences > Java > Code Style > Formatter but I was unable to find the settings for above.

The = should be placed in center with respect to alignment

Thanks for replying.

Upvotes: 0

Views: 532

Answers (2)

ankush yadav
ankush yadav

Reputation: 422

Go to same link as you mention window->prefernces->java->codestyle->formatter and Click on Edit Button.

and click on Align fields in columns see in image enter image description here

Edit:

you need to create new profile in eclipse on the same link. you can to change built in eclipse profile. see image.

enter image description here

Edit: Save Action:

enter image description here

Upvotes: 2

Ankit
Ankit

Reputation: 2753

You can use

CTRL+SHIFT+F

in eclipse to get the above format you have asked and also you can use

CTRL+A and then CTRL+I

to have correct indentation in eclipse.

Thanks, Ankit Shah

Upvotes: 0

Related Questions