The Artima Developer Community
Sponsored Link

Java Buzz Forum
Strings in Switch case - Java 7 Tutorial and Example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Strings in Switch case - Java 7 Tutorial and Example Posted: Dec 17, 2013 8:11 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Strings in Switch case - Java 7 Tutorial and Example
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Switch Statements are not new for any Programmer, it is available in C, C++, Java and in all major programming language. Switch statement in Java allows you to a clear, concise and efficient multiple-branch statement without lots and lots of messy if-else statement. But Java Switch and case statement has limitation, you cannot use String in them. Since String is one of the most used class in Java, and almost every program, starting from Hello World to complex multi-tier Java application uses them, it makes lot of sense to allow them in Switch case. In Java 6 and before, the values for the cases could only be constants of integral type e.g. byte, char, short, int and enum constants. If you consider Autoboxing then you can also corresponding wrapper class e.g. Byte, Character, Short and Integer. From Java 1.7, language has been extended to allow String type in switch and case statement as well. This makes, Java programmers life a bit easier, as it no more has to map String to Integers, to use them inside switch constructs. In this Java 1.7 tutorial, we will learn How to use Strings in switch in Java. Like many Project Coin enhancements, e.g. underscore in numeric literals, Automatic resource management,  this is really a very simple change to make life in Java 7 easier. This is not a JVM level change, instead it is implemented as syntactic sugar. In all other respects, the switch statement remains the same, and internally it uses equals and hashcode method to make it work.
Read more »

Read: Strings in Switch case - Java 7 Tutorial and Example

Topic: Constructor help Previous Topic   Next Topic Topic: 6 things you should know about Node.js

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use