In a project in IntelliJ IDEA, You want to count the line numbers for a given Java file.
We can count the line numbers in a Java file using the statistics plugin or regular expression.
IntelliJ IDEA Count line of code
There are multiple ways we can count the number of lines of code in the Editor.
using statistics plugin:
- Open IntelliJ IDEA editor
- Select
File
>Settings
, Open Settings Popup Window - Select
Plugin
> type “Statistic” in search plugins. - Click on the
Statistic
install button - Next, click on the Apply button and close the window
- You will see the bottom panel with statistics being selected.
- you can use see below option
Refresh
: It reloads and refreshes all the files in the project and calculates the statistics.Refresh on selection
: It selects selected files and output statistics.Settings
: Settings window
This plugin shows below the statistics of a given project or file.
- File size
- Lines count
- min size
- max size
Use the regular expression in Find and Search
- Open Edit > Find > Find or use shortcut command
Ctrl + F
- It opens the search box and selects
.*
icon (regex - Alt +X) - In the Search Box, Type below the regular expression
\n
: This includes the count of empty and non-empty lines and empty lines containing spaces.
\n+
: It gives only the count of non-empty lines of code.
- It gives the line number count displayed the beside search box