compare two strings in java

Ads

 
 
 

Share on Google+Share on Google+

Naulej kumar
compare two strings in java
1 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners

How to compare two strings in java?

Ads
View Answers

July 4, 2012 at 7:05 PM


package Compare;

public class StringTest {
    public static void main(String [] args){

        String str="Roseindia";

            String str1="Roseindia";

          if (str.compareTo(str1) == 0)

           {

 System.out.println("The two strings are the same.");

        }

     }

  }

Output:

The two strings are the same.

Description:-Here is an example of comparing two strings. By using the method compareTo, we have compared strings. If the strings are exactly the same, the compareTo method will return a value of 0 (zero).


Ads









Related Tutorials/Questions & Answers:
compare two strings in java
compare two strings in java  How to compare two strings in java...) { System.out.println("The two strings are the same."); } } } Output: The two strings are the same. Description:-Here is an example of comparing two
How do I compare strings in Java?
How do I compare strings in Java?  How do I compare strings in Java
Advertisements
Java : String Compare
Java : String Compare This tutorial demonstrate various way to compare two strings.  String Compare : In java, you can compare strings in many ways... the strings.  int compareTo( String anotherString ): This method compare two
Java : String Compare
Java : String Compare This tutorial demonstrate various way to compare two strings.  String Compare : In java, you can compare strings in many ways... the strings.  int compareTo( String anotherString ): This method compare two
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
Concatenating two Strings in Java
Concatenating two Strings in Java In this section we will help you, how to concatenate two strings in java. String are sequence of character which is used... that concatenate the two strings. String str1="hello"; String str2=" Java
Compare two word file
Compare two word file  How to compare two word file using Java
Compare two char array in java
Description: This tutorial demonstrate how to compare two character array are equal or not. The Arrays.equals(c1, c2) helps to compare it and return boolean value. Code: import java.util.Arrays
java program to compare two hashmaps and check whether they are equal or not
java program to compare two hashmaps and check whether they are equal or not  java program to compare two hashmaps and check whether they are equal
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
how to compare text in two jTextarea
how to compare text in two jTextarea  give some sample code
To get the String between two strings
To get the String between two strings  How to get string between two strings repeatedly using java?   Hi, Please tell me more about what do you want to achive. Thanks
Concatenate Two Strings in java
Concatenate Two Strings in java We are going to describe how to concatenate of two string. we have use for concat() method, this method joints of two string... taken two String string and string2.This keyword returns of String followed
Character Cases Ignoring case sensitiveness in java
to compare two strings ignoring case sensitiveness  Java provides the method... of code: compareToIgnoreCase(String str): This method is used to compare two strings.... The compareToIgnoreCase() method compares two strings and ignores its cases. This method
C String Compare
C String Compare       In this section, you will learn how to compare two strings. You can see in the given example, the program prompts the user to enter the two strings one
Compare two buffer's content
Compare two buffer's content In this tutorial we will see how to create a buffer and put content into it and compare byte data of one buffer with another. Code: import java.nio.CharBuffer
question about mixing two strings
question about mixing two strings  using java script we need to ask two strig and combine them like.. str1= helo str2= worl combined string= hweolrol
strings
strings  write a program in java to accept two strings as command line arguments and perform the following operations-: 1) compare the strings 2... is an example which accept two strings as command line arguments and perform
Compare string example
strings in java. The java lang package provides a method to compare two... you to compare the two strings. If both strings are equal, it will display... Compare strings example     
strings in java
strings in java  please explain me the flow of this program..not able to execute correctly n wats the use of clone public class Strclone { public static void main(String args[]) { String s=new String("a"); String s1
How to compare date in Java?
How to compare date in Java?  Hi, How to compare date in Java? Thanks   Hi, Check this example Date Comparison. Thanks
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
Comparing two dates in java
Comparing two dates in java In this example you will learn how to compare two dates in java.  java.util.Date provide a  method to compare two dates. The method which is used to compare the dates is "compareTo() "
Compare two double type buffer's content
Compare two double buffer's content In this tutorial we will see how to create a double buffer and put content into it and then compare double value of one buffer with another. Code: import 
Appending Strings - Java Tutorials
.style1 { text-align: center; } Appending Strings In java, the two... will compare the performance of these two ways by taking example. We will take three tasks to compare performance. For this we also crate a separate timer class
java program(strings) - Java Beginners
java program(strings)  Write a program in Java which accepts 2 strings as command line arguments. The program should do the following: i) print... both the strings to upper case iv) concatenate the two strings and finally
strings
strings  difference between the strings in java and c
hash function for java strings
hash function for java strings  hash function for java strings   int hash=7; for (int i=0; i < strlen; i++) { hash = hash*31+charAt(i
Comparing two Dates in Java with the use of after method
to compare two date objects in Java programming language. For comparing... Comparing two Dates in Java with the use of after method...() method to compare the dates. firstDate.after(secondDate); firstDate.after
Strings - Java Beginners
. eg: Obj o1=new Obj(); Obj o2=o1; But is case of Strings, how is it that two different object references are being created? String s1="Hello"; String
Grouping strings - Java Beginners
Grouping strings  I have written a code to determine the lengths of strings. What I need to do is to group strings that are within a certain range, say 15 to 20, 21 to 30, etc. Is there any one out there with an idea?  
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads