Iv been developing a parser using java, however due to testing on multiple machines i have errors now on one machine i corrected as the machine was using jdk/jre v1.6, and on my newer machine jdk/jre 1.7

The question i have is, what are the implications of using the String in a case statement in v1.7 vs the use of a series of if conditions that i implemented in java 1.6?

Will a String casestatement as a finite state machine perform any better or worse than lets say an optimal series of if conditions?

Is there any benefit to one over the other when it comes to string comparison?

Example :

If(testString.equals("test"))
{
return true;
}


Switch(testString)
{
case "Test": return true;
default : break;
}

Should i use the if conditons only for backwards compatibility in java versions?
What is the best structure to use for large string based state machines?

Any advice on any of those points will be appreciated :)

I hate to post a link to a different page but the explanation there seems clear.
Click Here

Summarizing it,the if-else_if-else statements will perform better in general cases because of the hash computation of the string that takes place when using switch statement with a String.To view the fully explained answer,click on the link provided.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.