How to Iterate backwards through a List?
- Sample JDBC connection creation
- How to set debugging details for eclipse
- Find Eclipse Plugins here!
- Code Review sample #1
- When working with a web application, what is the name of the deployment descriptor? Where is it located?
- Performance tips:Use of StringBuffer
- Open Closed Principle
- Stress Management
- Important Facts Of Life
- Making Dreams Come True
How to Iterate backwards through a List?
How to Iterate backwards through a List?
Do you know how to iterate backwards in a ArrayList?
Didn’t know, there is a ListIterator, which can be sued to iterate backwards in a list.
List<String> theTestList = new ArrayList<String>();
theTestList.add("a");
theTestList.add("b");
theTestList.add("c");
ListIterator<String> listIterator = theList.listIterator(theList.size());
while (listIterator.hasPrevious()) {
System.out.println(liter.previous());
}
How to use Collections.EMPTY_LIST with Generics?
How to use Collections.EMPTY_LIST with Generics?
Today I stumbled upon a nice solution, to use the Collections.EMPTY_LIST with Generics. Just use the method emptyList with Generics instead of the constant value.
Returns the empty list (immutable). This list is serializable.
For example:
Collections.<Holiday> emptyList();
List<String> s = Collections.emptyList(); this example illustrates the type-safe way to obtain an empty list:
Tip to avoid NullPointerException while using String
Tip to avoid NullPointerException while using String
There are many occasions where the logic/code in Java class needs to compare between a constant string value and a variable.
For example: variable.equals(STRING_CONSTANT);
Here if the variable is not initialized, then the above piece of code will throw a null pointer exception.
To shun this null pointer exception you can re-state the above piece of code as:
CONSTANT_STRING.equals(variable);
Always Follow Your Heart
Always Follow Your Heart
Your time is limited.
So don’t waste it living someone else’s life.
Don’t let the noise of other’s opinions
Drown out your inner voice.
Follow you heart. Always..
Follow you heart. Always..











