I heard that the new version of Java String made support in the operator Switch. Does it work now in Android?
            Asked
            
        
        
            Active
            
        
            Viewed 71 times
        
    0
            
            
        - 
                    http://stackoverflow.com/questions/14367629/android-coding-with-switch-string – Alexis C. Mar 27 '14 at 14:51
- 
                    2wasn't try yourself faster? – Karura91 Mar 27 '14 at 14:52
- 
                    you could resort to enums and their `valueOf(String)` to be used with switches – kiruwka Mar 27 '14 at 14:54
- 
                    @kiruwka That will only work for if your set of strings is limited. – m0skit0 Mar 27 '14 at 14:55
- 
                    @m0skit0 Definitely. But that is usually the case when you want to use switch, right ? – kiruwka Mar 27 '14 at 15:06
- 
                    @kiruwka Not necessarily, you might want to check several values and if it's not any of them do a default. – m0skit0 Mar 27 '14 at 15:18
1 Answers
2
            
            
        No. switch/case for String is only available for Java 7+, and Android Dalvik is based on Java 6.
EDIT: note that starting with API 16 there are some Java 7 features included, check this other answer.
- 
                    From the "other answer", it looks to me that some of those Java 7 features depend only on having a compiler that understands them, and is independent of what Android version is running on the device; and that `switch(String)` is one of those. Is my interpretation correct? – ajb Mar 27 '14 at 15:26
- 
                    @ajb Might be, I really don't know, that's why I'm referring to the other answer. Personally I've always used Java 6. – m0skit0 Mar 27 '14 at 16:13
 
     
    