- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Substring Comparisons
Following is an example which compares Strings and portion of strings in Java? Explain with an example.
Example
public class StringDemo { public static void main(String[] args) { String str1 = "tutorials point"; String str2 = str1.substring(10); int result = str1.compareTo(str2); // prints the return value of the comparison if (result < 0) { System.out.println("str1 is greater than str2"); }else if (result == 0) { System.out.println("str1 is equal to str2"); }else { System.out.println("str1 is less than str2"); } } }
Output
str1 is less than str2
- Related Articles
- String comparisons in Arduino
- Java substring() method example.
- Number comparisons in PHP 8
- Java String substring() Method example.
- File and Directory Comparisons in Python
- Remove substring from StringBuilder in Java
- How to use Java substring Method?
- Java Program for Anagram Substring Search
- Middle of three using minimum comparisons in C++
- What is the Purpose of Inter-Firm Comparisons?
- Role of Post Hoc comparisons in Research Psychology
- Display the position of a Substring in Java
- Count occurrences of a substring recursively in Java
- Java Program to locate a substring in a string
- Java Program to set a range for displaying substring

Advertisements