Good programming practices


Concise Java code

April 22nd, 2012

Here is an example how concise Java code can be. I wrote 2 methods that do the same, but looks different. It checks if an Iterable object has only one object, which is additionally equals to the one passed as the second argument. Both methods use Objects class added in Java 7. The first method use “&&” operator, which evaluates expression on right only when the left one was true. More…

How to iterate a list with index

April 10th, 2012

There is many ways to iterate a list or other collection in Java. Sometimes it is useful to have also current index, especially when it is a List, where the elements order matters. It can be achieved be several ways. Lets look at the example: More…