Special offers now — see discounted courses.
day
:
hour
:
min
:
sec
See special offers
Pattern Matching for Switch in Java 21

Pattern Matching for Switch in Java 21

41mIntermediate2025-06-20

Authors

Buddhini Samarakkody

Buddhini Samarakkody

Java Engineer, Author, Instructor

Course details

The course is designed for intermediate Java developers looking to upskill and grow their career. Join instructor Buddhini Samarakkody as she covers the essentials of the pattern matching feature for switch statements and expressions which was introduced in Java 21. Learn how patterns can be used in case labels of a switch statement or expression, using guarded patterns to further test if a value matches a pattern, the use of Java Records in switch, along with pattern matching. Along the way, Buddhini outlines the use of the null case label to avoid NullPointerExceptions in switch statements or expressions. By the end of this course, you’ll be equipped with the skills you need to write more readable, more concise, more powerful code.


Learning objectives
Identify the need for pattern matching for switch.
Write switch statements or expressions that contain patterns in case labels.
Demonstrate how to use null case labels in a switch statement or expression to prevent NullPointerExceptions.
Write switch statements or expressions that contain guarded patterns in case labels to further test if a value matches a pattern.
Demonstrate the use of switch statements and expressions that use Java Records for pattern

Skills covered

JavaOracleProgramming LanguagesSoftware DevelopmentOne-Off

Concepts

0. Introduction

  • 01 - Learning about pattern matching for switch
  • 02 - What you should know
  • 03 - Tour of CoderPad

1. The Background to Pattern Matching

  • 04 - What is pattern matching
  • 05 - Motivation - Pattern matching for instanceof
  • 06 - Evolution of switch in Java

2. Pattern Matching for Switch

  • 07 - Patterns in case labels
  • 08 - Using patterns in case labels
  • 09 - The null case label
  • 10 - Using the null case label
  • 11 - Guarded pattern case labels
  • 12 - Using guarded pattern case labels

3. Further Considerations

  • 13 - Ordering case labels
  • 14 - Exhaustiveness of a switch block
  • 15 - Using record patterns with switch

Conclusion

  • 16 - Next steps

Related courses

Related learn paths

About us

LyndaKade is a leading learning platform that helps people learn business, software, technology, and creative skills to achieve personal and professional goals.

Phone numberAparat ChannelTelegram SupportTelegram ChannelInstagram Page

All rights to this site belong to LyndaKade.

Terms of Service|Privacy Policy

نماد الکترونیک enamad در صورت اتصال با آی‌پی داخل کشور، نمایش داده خواهد شد.
logo-samandehi - لوگو ساماندهی
zarinpal
zibal