I have the following code snippet:
Set<Company> companiesByUserName = companyUserService.getCompaniesByUserName(username);
Using IntelliJ live templates, I know I can type "itco" and it will generate the following for me:
for (Iterator<Company> iterator = companiesByUserName.iterator(); iterator.hasNext(); ) {
Company next = iterator.next();
}
However, how can I automatically create a foreach with the 'companiesByUserName' variable instead? So I want it to generate this automatically:
for (Company company: companiesByUserName) {
}
Because the foreach is a lot cleaner that iterating through the collection in a for loop, I generally use those instead, so would like to auto generate them if possible.
There is also a new feature introduced with IJ 13, called postfix completion. With that, you can type companiesByUserName.for
and hit TAB (and obviously much more as per your defined templates):
Nevermind, found out how to do it. Just type "iter" and press enter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With