eclipse and line wrapping

Last month, a co-worker referenced an Eclipse setting that I wish I’ve known about for years.  With streams, I typically indent code like:


list.stream().filter(j -> j.disabled)

.map(j -> j.name)

.forEach(System.out::println);

Then I’d let Eclipse format the code and it would turn into a one (or two) line wall of text. I’ve been “solving” that problem by adding comments before some of the methods so Eclipse couldn’t wrap it. Some of those comments are useful for those new to streams. However many are redundant. You probably don’t need a comment that the last line outputs :).

Then my co-worker taught me that there is an Eclipse setting to control the line breaks. Wish this was on by default!

How to configure

If you don’t already have a custom Eclipse formatter:

  1. Eclipse preferences
  2. Java > Code Style > Formatter
  3. New
  4. Enter a name
  5. Click ok

Control line breaks

  1. Edit the profile
  2. Line wrapping tab
  3. Check “Never join already wrapped lines”