Skip to content

A beginner-friendly demonstration of why == doesn't work for String comparison in Java, with memory management explanations. Learn the difference between reference and value comparison.

Notifications You must be signed in to change notification settings

kanishkaGayan/java-string-comparison-explained

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Java String Comparison: Reference vs Value

A practical guide for Java beginners explaining why == operator fails for String comparison and why .equals() method should be used instead. This repository includes working code examples demonstrating the difference between reference comparison and value comparison, with detailed explanations of Java's memory model (Stack vs Heap).

What You'll Learn

  • The difference between primitives and objects in Java
  • How Stack and Heap memory work
  • Why == compares references (memory addresses)
  • Why .equals() compares actual content
  • Best practices for String comparison in Java

Perfect for beginners who encountered the "String values are compared using '==', not 'equals()'" warning and want to understand the underlying reason.

fore more details : Read >

About

A beginner-friendly demonstration of why == doesn't work for String comparison in Java, with memory management explanations. Learn the difference between reference and value comparison.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages