Home Answers Viewqa Java-Beginners Comparing strings

 
 


Barry
Comparing strings
2 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners

View Answers

August 12, 2008 at 4:15 PM


Hi friend,

import java.lang.*;
import java.io.*;

public class CompareString{
public static void main(String[] args) throws IOException{
System.out.println("String are equal and not equals");
BufferedReader item = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter First String:");
String item1=item.readLine();
System.out.print("Enter Second String:");
String item2=item.readLine();
char c1=item1.charAt(0);
char c2=item2.charAt(0);
char c3=item1.charAt(1);
char c4=item2.charAt(1);

if( item1.equals(item2)){
System.out.println("The given string is equals.");
}
else{
System.out.println("The given String is not equals.");
}
}
}

--------------------------------------------------------------


Read for more information.

http://www.roseindia.net/java/

Thanks.

Amar

August 12, 2008 at 5:37 PM


hai frnd......
i think this would help u....


import java.io.*;
class Substring
{
public static void main(String a[])throws Exception
{
String str,sub;
int i=0,k=0;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String: ");

str=br.readLine();
System.out.println("Enter the subString: ");
sub=br.readLine();
while(i<str.length())
{

if(str.indexOf(sub)>=0)
{
k++;
str=str.substring(str.indexOf(sub)+1);
}

i++;
}
System.out.println("The number of times is: "+k);
}
}



inform me if it works...

thanks and regards
prashu
prashobvee@gmail.com









Related Pages:
Iphone Comparing Strings
Iphone Comparing Strings  Hi, I am very new in the mobile application programming. I have trying to develop a small application for IPhone SDK Comparing Strings. Could any one suggest or provide any examples topics iphone sdk
Comparing strings - Java Beginners
Comparing strings  Can anyone help with finding the number of time(s) a substring appears in a string? The code I've written can get it once and after that cannot continue to the end of the string.  Hi friend, import
iPhone SDK Comparing Strings
of comparing strings in iPhone sdk programs. The == operator only compares the pointers, but instead we are comparing the the actual strings.  Hope the above...In this section I will show you how you can compare the two strings in your
Comparing Strings in a Locale-Independent Way
Comparing Strings in a Locale-Independent Way In this section, you will learn how to compare strings in a locale independent way. For handling strings, java.text.* package provides the class Collator. This class performs locale
String Comparison
the characters in the strings. Comparing objects vs. primitive types [to be supplied] Comparing Strings: ==, .equals(), .compareTo(), ... To compare Strings... Java NotesString Comparison Strings can not be compared with the usual <
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...compare two strings in java  How to compare two strings in java
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
strings
strings   read sentence and convert all the word into capital case like camelcase   Hi Friend, Try the following code: import java.util.*; class ConvertWordsIntoUpperCase { public static String toCamelCase(String
Strings
will contain strings which is separated by ",". From the main method invoke
Comparing tables
Comparing tables  How to compare two or more tables in the Mysql database using jdbc
String comparison example
:- There are many comparison operators for comparing strings like <, <=, !=, ==, =>, and >. Action script  compare strings on the character code value...; operator for compare two strings. Example:- <?xml version="
comparing dates objective c
comparing dates objective c  Comparing two different dates in Objective C.   if( [date isEqualToDate:otherDate] ) NSLog(@"%@ is equal to %@",date,otherDate);   Objective C NSString Date Example
==, .equals(), and compareTo()
sort() method or ordered data structures. Comparing Object... with object references are comparing for equality (==) and inequality... strings together or taking the substring), even though name really does
Comparing XML with HTML
Comparing XML with HTML XML and HTML are both designed for different purposes. Although they have some similarities in markup syntax but they are created for different types of goals. XML is not at all the replacement of HTML
Character Comparison Example
in Java. The java.lang package provides a method for comparing two case sensitive  strings. The compareTo() method compares two strings on the basis of Unicode of each character of the given strings. This method returns integer type
strings concatnation
strings concatnation  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic
comparing arraylist of an multi dimensional arraylist
comparing arraylist of an multi dimensional arraylist  can anyone help me in solving the following issue: actually i have an arraylist called dany under which there are 89 more arraylist.each of them contains some values.now i
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
strings 20june
strings 20june  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 = "Hello
programes on strings
programes on strings   a. write a program to copy one array to another array using System.arrayCopy() method. b. write a program to check whether entered string is palindrome or not.   Have a look at the following link
split strings in php
split strings in php  how can i split strings in word pair in PHP
Insane Strings - Java Tutorials
Insane Strings 2001-03-21 The Java Specialists' Newsletter [Issue 014] - Insane Strings Author: Dr. Heinz M. Kabutz If you are reading this, and have... mutate Strings. Thanks if you forwarded last week's newsletter to some
to retrieve from radiobox and comparing with a string - Struts
to retrieve from radiobox and comparing with a string  im creating a exam application in jsp which makes students to attend java questions.. created an array of radio buttons below is the code
Java : String Compare
strings.  String Compare : In java, you can compare strings in many ways... the strings.  int compareTo( String anotherString ): This method compare two... compareToIgnoreCase( String anotherString ): This method compare two strings ignoring
Java : String Compare
strings.  String Compare : In java, you can compare strings in many ways... the strings.  int compareTo( String anotherString ): This method compare two... compareToIgnoreCase( String anotherString ): This method compare two strings ignoring
Comparing Two Numbers
Comparing Two Numbers      ... of comparing two numbers and finding out the greater one. First of all, name a class... a. class  Comparing{   public static 
Comparing two Dates in Java
Comparing two Dates in Java   ... using java.util.Date class. For comparing dates, we will be using compareTo() method. The compareTo() method returns integer value after comparing the dates
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method... of comparing dates you have seen how to use after() method in java class for comparing... with the use of java.util.Date class. For comparing date we are using before() method
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
To check the Rotational Strings are Equall or not
To check the Rotational Strings are Equall or not  I attended 3dplm software company interview....there asked one question related to Strings.The question is................. Write a program to check the given two strings
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?  
Strings - Java Beginners
Strings  Normally when we assign one object to the other, a copy of the reference is created and both these references point to the same object. eg: Obj o1=new Obj(); Obj o2=o1; But is case of Strings, how
convert numbers to strings using JavaScript
convert numbers to strings using JavaScript  How to convert numbers to strings using JavaScript
searching for strings in a file
searching for strings in a file  how can i search of a person and display the other details associated with the name using java gui window?   import java.util.ArrayList; import javax.swing.*; import java.awt.event.
Appending Strings - Java Tutorials
.style1 { text-align: center; } Appending Strings In java, the two main ways for appending string at the end are : First method is using += operator. Second method is using append()  method. In this section, we
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... in both the strings ii) replace every occurrence of ?a? or ?A? by @ iii) convert

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.