Monday, June 30, 2025
How to sort an Array in Java? Ascending and Descending Order Example
How to loop through an Array in Java? Example Tutorial
How to declare and initialize a List with values in Java (ArrayList/LinkedList) - Arrays.asList() Example
How to implement Skip List in Java? Example Tutorial
Hello friends, we meet again today. hope you all are excited and ready for today's journey. Today, we are gonna learn something that is not very common. It is used not very common, but, if used, it is a great strength to our time complexity reduction. So, what's the wait? Let's start! So, suppose we have a linked list with us which has 10 million records. Now, for searching a particular node, the time taken would be O(N). Where N is the size of the list. Similarly, the time taken for deletion of a Node, Insertion at a particular Node will also take O(N) time. Can we reduce it?
How to find If Linked List Contains Loop or Cycle in Java? Example Solution
How to use Array in Java? Example Tutorial
Top 15 Data Structures and Algorithm Interview Questions Answers for Java Programmer
Difference between Stable and Unstable Sorting Algorithm - MergeSort vs QuickSort
Saturday, June 28, 2025
How to Count Number of Leaf Nodes in a Binary Tree in Java ? [ Iterative and Recursive Solution]
6 ways to declare and initialize a two-dimensional (2D) String and Integer Array in Java - Example Tutorial
How to implement Bucket Sort in Java? [Solved] - Example Tutorial
Recursive Binary Search Algorithm in Java - Example Tutorial
Difference between Stack and Queue Data Structure in Java? Example
Difference between Comparison (QuickSort) and Non-Comparison (Counting Sort) based Sorting Algorithms? Example
How to implement Post Order Traversal of Binary Tree in Java - Recursion and Iteration Example
How to Implement Binary Search Tree in Java? Example
Friday, June 27, 2025
How to Compare Arrays in Java – Equals vs deepEquals Example
Recursion in Java with Example – Programming Tutorial for Beginners
3 Examples to Print Array Elements/Values in Java - toString and deepToString from Arrays
Iterative QuickSort Example in Java - without Recursion
4 Ways to Search Java Array to Find an Element or Object - Tutorial Example
How to loop over two dimensional array in Java? Example
2 Examples to Convert Byte[] Array to String in Java
How to Fix Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: in Java? Solution
Thursday, June 26, 2025
How to remove all special characters from String in Java? Example Tutorial
StringTokenizer Example in Java with Multiple Delimiters - Example Tutorial
How to replace a substring in Java? String replace() method Example Tutorial
How to check if String contains another SubString in Java? contains() and indexOf() example
How to check if a String is numeric in Java? Use isNumeric() or isNumber() Example
How to split String in Java by WhiteSpace or tabs? Example Tutorial
Java String Replace Example Tutorial
How SubString method works in Java - Memory Leak Fixed in JDK 1.7
How to use String in switch case in Java with Example
How to String Split Example in Java - Tutorial
I don't know how many times I needed to Split a String in Java. Splitting a delimited String is a very common operation given various data sources e.g CSV file which contains input string in the form of large String separated by the comma. Splitting is necessary and Java API has great support for it. Java provides two convenience methods to split strings first within the java.lang.String class itself: split (regex) and other in java.util.StringTokenizer. Both are capable of splitting the string by any delimiter provided to them. Since String is final in Java every split-ed String is a new String in Java.
How to convert String or char to ASCII values in Java - Example Tutorial
int asciiOfA = (int) 'A';
Here casting is not necessary, simply assigning a character to an integer is enough to store the ASCII value of character into an int variable, but casting improves readability.
byte asciiOfB = 'B'; // assign 66 to variable
How to format String in Java – String format Example
How String in Switch works in Java? Example
10 Things Every Java Programmer Should Know about String
How to Split String based on delimiter in Java? Example Tutorial
String replaceAll() example - How to replace all characters and substring from String
Wednesday, June 25, 2025
Why character array is better than String for Storing password in Java? Example
How to Compare Two Strings Without Case Sensitivity in Java? Example
How to Compare Two Strings Without Case Sensitivity in Java
Java provides several ways to compare strings without taking case sensitivity into account. In this article, we'll explore different methods to perform case-insensitive string comparisons in Java.
Method | Use Case | Efficiency |
---|---|---|
equalsIgnoreCase() | Checking equality | High |
compareToIgnoreCase() | Ordering comparison | High |
String.CASE_INSENSITIVE_ORDER | Sorting collections | High |
equals() + toUpperCase() | Not recommended | Low |
1. Using equalsIgnoreCase()
The equalsIgnoreCase() method
This method is ideal for checking if two strings are equal without considering their case. It returns true if both strings contain the same characters, regardless of their case.
String str1 = "Hello";
String str2 = "hello";
boolean isEqual = str1.equalsIgnoreCase(str2); // Returns true
2. Using compareToIgnoreCase()
The compareToIgnoreCase() method
Use this method when you want to check which string is greater or smaller, or to find out their relative ordering in lexicographical or alphabetical order, without considering case.
String str1 = "Apple";
String str2 = "banana";
int result = str1.compareToIgnoreCase(str2); // Returns a negative value
3. Using String.CASE_INSENSITIVE_ORDER
The String.CASE_INSENSITIVE_ORDER comparator
This comparator is useful for sorting a list of strings in case-insensitive order.
List<String> fruits = Arrays.asList("Apple", "banana", "Cherry");
Collections.sort(fruits, String.CASE_INSENSITIVE_ORDER);
// Result: [Apple, banana, Cherry]
4. Using equals() + toUpperCase()
Combining equals() and toUpperCase()
This is a tricky way to compare two strings in Java in a case-insensitive manner. First, convert both strings to uppercase, then compare them using equals().
String str1 = "Hello";
String str2 = "hello";
boolean isEqual = str1.toUpperCase().equals(str2.toUpperCase()); // Returns true
Note: This method is not recommended as it creates new String objects, which can be inefficient for large-scale comparisons.
Conclusion
When comparing strings without case sensitivity in Java, it's generally best to use the built-in methods like equalsIgnoreCase()
for equality checks and compareToIgnoreCase()
for ordering comparisons.
These methods are optimized and provide clear, readable code. For sorting collections of strings, the String.CASE_INSENSITIVE_ORDER
comparator is an excellent choice.
Remember, all these methods compare strings in lexicographical order. Choose the method that best fits your specific use case to ensure efficient and accurate string comparisons in your Java applications.
2 Ways to remove whitespaces from String in Java? Example Tutorial
Difference in String pool between Java 6 and 7? Answer
10 Difference between StringBuffer and StringBuilder in Java? [Answered]
How to Convert and Print Byte array to Hex String in Java? Example
StringJoiner.join() and String.join() Example in Java 8
3 ways to convert String to Boolean in Java? Examples
Tuesday, June 24, 2025
Top 15 Java String interview Question Answers for 3 to 5 Years Experienced
String interview questions in Java is one of Integral part of any Core Java or J2EE interviews. No one can deny the importance of String and how much it is used in any Java application irrespective of whether it's core Java desktop application, web application, Enterprise application or Mobile application. The string is one of the fundamentals of Java programming language and correct understanding of String class is a must for every Java programmer. What makes String interview questions in Java even more interesting is the special status of String in terms of features and privileges it has like the + operator is kind of overloaded to perform String concatenation despite the fact that Java does not support operator overloading. There is a separate String pool to store String literal etc.
How to compare two String in Java - String Comparison Example
How to Remove First and Last Character of String in Java - Example Tutorial
How to get first and last character of String in Java - Example
How to check if String is not null and empty in Java? Example
When to use intern() method of String in Java? Example
How to split a comma separated String in Java? Regular Expression Example
Why String is Immutable or Final in Java? Explained
Sunday, June 22, 2025
How to Convert an Array to Comma Separated String in Java - Example Tutorial
Friday, June 20, 2025
Top 10 Low Latency Tips for Experienced Java Developers
Hello guys, If you are preparing for interviews at High-Frequency Trading (HFT) firms, hedge funds, investment banks, or crypto exchanges, then one thing is guaranteed: You will be asked about low latency systems. Building such systems is a completely different ball game. It’s not just about writing clean code — it's about writing fast code that responds in microseconds. I’ve worked on low-latency Java applications that run in production under tight time constraints, and in this post, I’ll share what I’ve learned in easy Indian English, with some practical examples.
Thursday, June 12, 2025
Difference between Stack and Heap memory in Java? Example
What is load-on-startup servlet element in web.xml with Example?
Difference between SendRedirect() and Forward() in JSP Servlet? Example
Difference between throw and throws in Exception handling - Java Example
Difference between Struts 1 and Struts 2 Web Development Framework
10 points on finalize method in Java – Tutorial Example
What is Static and Dynamic binding in Java with Example
Wednesday, June 11, 2025
3 Examples to Concatenate String in Java
3 Ways to Convert an Array to ArrayList in Java? Example
Have you encountered any situation where you quickly wanted to convert your array to ArrayList or ArrayList to array in Java? I have faced many such situations that motivate me to write these quick Java tips about converting an array to ArrayList and ArrayList to array in Java. Both array and ArrayList are quite common and every Java developer is familiar with this. Former is used to store objects and primitive types while later can only hold objects. The array is part of standard Java fundamental data structure while ArrayList is part of the collection framework in Java.