The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »

Jdk7 - String in Switch


Before JDK 7, only integral types can be used as selector for switch-case statement. In JDK 7, you can use a String object as the selector.

equals() and hashcode() method from java.lang.String is used in comparison, which is case-sensitive. Benefit of using String in switch is that, Java compiler can generate more efficient code than using nested if-then-else statement.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com