How Do You Compare Strings in Java: equals, compareTo and ignoreCase?
Use equals for content, equalsIgnoreCase to ignore case and compareTo for ordering. See why == is wrong and how to avoid NullPointerException.
2,881 posts about Java: questions with answers, tutorials and articles, newest first.
Use equals for content, equalsIgnoreCase to ignore case and compareTo for ordering. See why == is wrong and how to avoid NullPointerException.
Java is strictly pass by value, even for objects. Learn how references are copied, why swap fails and why Strings never change inside a method.
Recursion in Java is a method calling itself on a smaller input. See how the call stack works, classic examples and how to avoid StackOverflowError.
Varargs lets a Java method accept zero or more arguments of one type as an array. Learn the rules, overload resolution and the common pitfalls.
Methods in Java are named blocks of code you define once and call many times. See the syntax, parameters, return types and static versus instance methods.
A two-dimensional array is an array of arrays that models rows and columns. Learn to create, loop over, print and copy 2D and jagged arrays in Java.
An array holds a fixed number of values of one type. Learn to declare, fill, loop over, copy and sort arrays, and avoid index and reference mistakes.
Java offers for, while and do-while loops for repeating code. See how each works, when to pick it, and how break and continue change the flow.
Java chooses which block to run from boolean conditions. See the syntax of if, else if and else, how chains are evaluated, and which mistakes to avoid.
Variable scope decides where a name can be used. Learn how local, instance and class variables differ in visibility, lifetime and default values.
The ternary operator picks one of two values from a boolean condition. See its syntax, how it differs from if-else, and the type and null traps to avoid.
The Scanner class reads keyboard input in Java. See how to read numbers and text, avoid the nextLine bug and validate input.
Bitwise operators act on individual bits and shifts move them. See &, |, ^, ~, <<, >> and >>> with masks, tricks and pitfalls.
Operators in Java calculate, compare and combine values. See arithmetic, relational and logical operators with traps like integer division.
Type casting in Java converts values between types. Learn implicit widening, explicit narrowing, overflow traps and safe reference casts.
A Java variable is a named, typed storage location. See how to declare and initialize it, its scope, final constants and var inference.
Packages group related Java classes into namespaces and imports let you use them by short name. See declarations, import forms and how to compile.
Learn the three kinds of Java comments, how to write Javadoc, and the naming conventions for classes, methods, variables, constants and packages.
JShell is the Java REPL included in the JDK since Java 9. Run expressions, methods and classes instantly without a main method.
Install IntelliJ IDEA, create a Java project with a JDK, run a first class and pick up the beginner shortcuts, settings and fixes that matter.