About 359,000 results
Open links in new tab
  1. Use string in switch case in java - Stack Overflow

    Apr 20, 2012 · Java (before version 7) does not support String in switch/case. But you can achieve the desired result by using an enum. private enum Fruit { apple, carrot, mango, …

  2. String in Switch Case in Java - GeeksforGeeks

    Jul 11, 2022 · Given string str, the task is to write a Java program to swap the pairs of characters of a string. If the string contains an odd number of characters then the last character remains …

  3. Strings in switch Statements - Oracle

    The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using the String.equals method; consequently, the …

  4. java string.contains in switch statement - Stack Overflow

    Jul 19, 2012 · Condition matching is not allowed in java in switch statements. What you can do here is create an enum of your string literals, and using that enum create a helper function …

  5. Switch Case with string Java - Stack Overflow

    Jan 12, 2012 · Here is an example how to use strings in switch case... option = scanner.nextLine(); switch (option) { case "1": System.out.println("Hello");break; case "2": …

  6. Switch Statements in Java - GeeksforGeeks

    Apr 11, 2025 · Starting from Java 7, switch statements can use String type values. They can also handle wrapper classes like Integer, Short, Byte, Long. Java switch expression must be of …

  7. Java String Switch Case Example

    May 16, 2019 · Learn how to use strings in switch case statements, string switch case null and case insensitive check.

  8. Java switch case String - DigitalOcean

    Aug 4, 2022 · Java switch case String make code more readable by removing the multiple if-else-if chained conditions. Java switch case String is case sensitive, the output of example confirms …

  9. Switch Case Java String: A Guide - JA-VA Code

    Sep 28, 2023 · In this detailed guide, we’ll dive into the world of the switch statement in Java for strings. We’ll explore its syntax, usage examples, best practices, and potential pitfalls. Before …

  10. Java Switch Statement - Baeldung

    Jun 11, 2024 · Below we’ll give some code examples to demonstrate the use of the switch statement, the role of the break statement, the requirements for the switch argument/case …

Refresh