Debugger: Filtering Arrays & Collections in IntelliJ IDEA 2017.2

As usual, the newest version of IntelliJ IDEA contains updates to help you debug applications.  Given that we are working more and more with large data sets, IntelliJ IDEA 2017.2 has added the ability to filter arrays and collections in our variables or watches.

Breakpoint during debugging

In this example, I have a variable allWords that’s a list of Strings. This is a large list, so when I’m debugging my application I may want to look for specific values, or types of values, in this list.  I can do this by right-clicking on the list and selecting “filter”.

Select "filter" on a list or array

Then I can enter the criteria to filter. As you’d expect, IntelliJ IDEA offers code completion and suggestions here.

Code completion on the filter field

The debug window will now show me the subset of values in the list that match this criteria.

List filtered by start of word

If I right click on the filter, I can edit the filter to change the original criteria or add further filters

The filter can be changed

And I can easily remove the filter using the clear button.

Press clear to remove the filter

This feature also works on other Collection types, and arrays.  Here, we’ve added a watch expression that creates an array of random ints

An int array in watches

We can filter these values too

A filtered list of ints

This ability to filter the values in large collections like lists and arrays make it easier for us, as we’re debugging an application, to see which values are available, and particularly if one or more of them match some criteria we’re looking for.

Comments below can no longer be edited.

7 Responses to Debugger: Filtering Arrays & Collections in IntelliJ IDEA 2017.2

  1. Avatar

    Yunti says:

    August 3, 2017

    Is this also available in pycharm as I can’t see it in the current version (2017.2)?

  2. Avatar

    Michał Rowicki says:

    August 11, 2017

    How can I use it with Maps? All the time I see Error, that I can not use operations on HashMap$Node

    • Avatar

      egor.ushakov says:

      August 14, 2017

      This is strange, please file a bug https://youtrack.jetbrains.com/issues/IDEA.
      I tried it with a simple filter like “this.getKey().contains(“x”)” and it worked well.

  3. Avatar

    aqqa says:

    September 30, 2019

    There should be an option to count filered elements…

  4. Avatar

    xiejx618 says:

    April 17, 2020

    How to use it in idea 2020,Why did I not prompt after using “this”, and it didn’t work

Discover more