Hi all,
I have a situation where am using String conditions(say if(name.equalsIgnoreCase(Arathy)).
I want to replace this if-else loop with Switch cases..What way i can do to accomplish this?
Hi all,
I have a situation where am using String conditions(say if(name.equalsIgnoreCase(Arathy)).
I want to replace this if-else loop with Switch cases..What way i can do to accomplish this?
depends, what JDK have you installed?
using switch-case on String objects has only been implemented since Java 7
if you work with a previous version, you can always keep a String array of the possible answers and use the index as switch value.
If those string belong to a fixed set of values, consider using an enum instead of strings which have the added benefit of type safety. There might be other ways of achieving what you desire but difficult to suggest without more context.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.