Which code runs faster and is less error prompt (more accurate)?
Answer: In this specific case performance is not the issue. Because no matter how you are going to use this actual execution numbers are same. But you can improve the code readability and making it less errorprone.
Instead of worrying about performance, start with SOLID principle. Why don't you just break this big method into some smaller method which has a concrete responsibility. It will make code more beautiful and less error prone. For example:
Methods:
void processA(int number){
switch (number) {
case 1:
.........
case 2:
.........
case 3:
.........
}
}
void processB(int number){
switch (number) {
case 1:
.........
case 2:
.........
case 3:
.........
}
}
///
now from the main method you could simply call:
if (letter.equals(a)) {
// call the method which will process A
processA(number);
} else if (letter.equals(b)) {
// call the method which will process A
processB(number);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…