When we’re writing code, we’re always going to do some traversal of an array or a collection.

You’d be smart to quickly insert something like the following, which defines an int I, and then I starts at 0 and iterates over the collection.

 for (int i = 0; i < testList.size(); i++) {
        }
Copy the code

Fori solutions for IntelliJ IDEA

In the blank, type for

After you type for, you should be able to see the small window below.

In the small window above, select Fori and your IntelliJ IDEA will automatically insert the code below for you.

for (int i = 0; i < ; i++) {
            
        }
Copy the code

Using the code above, you don’t have to hit the definition of int I again.

Helps you get out of the trouble of defining integers.

Foreach solution from IntelliJ IDEA

We know that there is another way to write Java loops after JDK 5.

Here, you can use the Foreach solution.

Foreach’s solution above will help you insert:

        for (:
             ) {
            
        }
Copy the code

This statement.

You can then iterate through the collection directly in the above statement.

conclusion

Using IntelliJ IDEA shortcuts and syntax hints can help us improve coding efficiency.

Iterating through or looking up collections is often used in programs, so hopefully this tip will help save typing on variable definitions.

www.ossez.com/t/intellij-…