April 19, 20232 yr comment_91858 Assuming your source is compatable with Java 13 you could use enhanced Switch as shown below and if your using java 17 LTS you could move to using Switch Expressions they are very beautiful even more so if you are using Arrays with named types. Fun fact for anyone that is Beginner to Intermediate with the Java Programming Language did you know that Switch Cases are typically faster once compiled into byte code assuming you are using java conventions and using a modern JVM similar to Java 17. Just using one or two if statements will be faster than using Switch or Switch Expressions but if you look at most Server Applications they are riddled with if statements paired with ugly outdated and depressingly complex for a simple task. Meet Easier This is the hidden content, please Sign In or Sign Up The First Part This is the hidden content, please Sign In or Sign Up This assumes you have added anything useful yet here is the first switch statement This is the hidden content, please Sign In or Sign Up yes this works just fine but its freaking ugly also not using break; or return; on each case also slows down the byte code optimizations as it skips and moves threw each case.
Create an account or sign in to comment