C
cruster
Is it possible to achieve something like this?
switch (mystring.charAt(0)) {
case 'a'..'z':
// do something
break;
}
switch (mystring.charAt(0)) {
case 'a'..'z':
// do something
break;
}
cruster said:Is it possible to achieve something like this?
switch (mystring.charAt(0)) {
case 'a'..'z':
// do something
break;
}
Is it possible to achieve something like this?
switch (mystring.charAt(0)) {
case 'a'..'z':
// do something
break;
}
Luc said:There are times when an if statement may be more appropriate
Sorry - java is not VB
cruster said:case 'a'..'z':
cruster said:Is it possible to achieve something like this?
switch (mystring.charAt(0)) {
case 'a'..'z':
// do something
break;
}
cruster said:Is it possible to achieve something like this?
switch (mystring.charAt(0)) {
case 'a'..'z':
// do something
break;
}
Oo, good point Something that's easy for C programmers to trip up
on...
Luc said:There are times when an if statement may be more appropriate
Dale King said:And I don't think this is one of those cases! Switch statements should
support ranges and value lists. I submitted an RFE for such a feature
years ago:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4269827
Using a switch is more readable than the if-else and can actually be much
more efficient than if-else (see the comments I attached to the RFE).
Luc said:The listed example is basically an if statement. If there were even 1 or 2
other cases I would not have a problem with it.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.