In the name of Allah, Most Gracious, Most Merciful

Sunday, August 1, 2010

Java Tips.

1] Java Enhanced For Loop ::

http://www.java-tips.org/java-se-tips/java.lang/the-enhanced-for-loop.html


[Sample Code]

String[] array = {"Ahmed","Mohamed","Salama"};
for(String i:array){
System.out.println(i);
}


output :: Ahmed Mohamed Salama

2] Using Generics ::

Use it if you needed to restrict your collection to a specific type.

[Sample Code]
Stack s = new Stack();
s.push(10);
int temp = s.pop();

: would restrict the Stack to Integer only .. now you don't need to cast the result of s.pop() every time you pop an element .. on the other hand, the compiler should through an error if y
s than Integers ..

More tips to follow isAllah :) ...
ou tried to push other data type

No comments:

Post a Comment