Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java String searching.

Have Programming Question? Ask it here!
 
 
 


ratna rathor
Java String searching.
1 Answer(s)      a year and 11 months ago
Posted in : Java Beginners


How to search a string in given String array?


Advertisement
View Answers

May 18, 2012 at 2:32 PM


import java.util.Scanner;

public class StringSearch {
    public static void main(String[] args) {
        String city[] = { "Delhi", "Lucknow", "Mumbai", "Kanpur" };
        String userCity;
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter city name you want to search in list: ");
        userCity = scanner.next();
        int i = 0;
        int flag = 0;
        while (i < city.length) {

            if (userCity.equalsIgnoreCase(city[i])) {
                flag = 1;
                break;
            } else {
                flag = 0;
                i++;
            }
        }
        if (flag == 1) {
            System.out.println("City found");
        } else {
            System.out.println("Try another city");
        }
    }
}

Description: We have taken a String array of city.User will input its city and for searching we used userCity.equalsIgnoreCase(city[i])). EqualsIgnoreCase() method is used to search without caring of case. you can also use equals() method if string case is considered.



Related Tutorials/Questions & Answers:
Java String searching.
Java String searching.  How to search a string in given String array... static void main(String[] args) { String city[] = { "Delhi", "Lucknow", "Mumbai", "Kanpur" }; String userCity; Scanner scanner = new
searching a text string in file - Java Beginners
searching a text string in file  code to match a string in a file that is already mentioned in java code.if the string matches any part of a string that whole string is printed
Advertisements
searching string
searching string   how to write a program for searching a string...{ public static void main(String[] args){ Scanner input=new Scanner(System.in); System.out.println("Enter string: "); String str = input.nextLine
Searching English words in a string
Searching English words in a string  My task is to find English words and separate them from a string with concatenated words..for example...(String[]args){ String st="AhdgdjHOWAREgshshYOUshdhfh"; char ch
Java Sorting and Searching
Java Sorting and Searching   If anyone could help me with this I would be really thankful! Write a program that stores the names of these artists in a String array. The program should prompt the user to enter the name
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching operation in JAva
Searching operation in JAva  Sir, I have made a project for the Dispatch section of my office. I have to search for letters that are dispatched on a particular date. Now there are thousands of letters dispatched on a particular
Searching with alphabetical order - Java Beginners
Searching with alphabetical order  Hi, I want to this please help me Steps:- 1:-I have a one form of name text box with two button. 2:-user input in name text box(alphabetical order)search all fields from
Searching with alphabetical order - Java Beginners
Searching with alphabetical order  Hi, please understood my problem and send write code its very urgent I a write once again. Steps.... 2:-User input in the name text box(searching alphabetical order) name
Searching a tex on a table in java! - Java Beginners
Searching a tex on a table in java!  i have a table which contains several data. using a textfield the item hat i search must be selected... the problem. For more information on Java visit to : http://www.roseindia.net
searching technique
searching technique  Hi, i need any searching technique in java to search the data and give the all possible data by links
searching problem
searching problem  how we can make a code in core java for searching in hard disk? i have to make an antivirus as my minor project , so i have need this type code to search the virus in hard disk
searching problem
searching problem  how we can make a code in core java for searching in hard disk? i have to make an antivirus as my minor project , so i have need this type code to search the virus in hard disk
searching books
searching books  how to write a code for searching books in a library through jsp
file searching
file searching  i need a prog for searching inside a text file after evry 1 min to find does it hav any new entry
searching the data
searching the data  respected sir , i am making the desktop application , so how can i search the data which are stored in the mysql databses through click the button and display in jtable through netbeans dynamically
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
Sorting and Searching
help me with this A program is required to ask users to rate the Java... java.util.*; class RateJava { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Rate Java(0-10
Searching - Hibernate
{ public static void main(String[] arg){ Session session = null; try...(); String SQL_QUERY = "from RecordInformation as record where record.userid LIKE... RecordInformation { private String userid; private String lastname; private String
Java String
Java String  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon as possible Thank you
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?  ...*; class Book{ int bookid; String title; String author; Book(int
searching inside a file for details
searching inside a file for details  i created a file with name,country,state etc...when i'm searching for the name, i have to get other details like country,state etc...please do help
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
Java String - Java Beginners
Java String  How to seperate the string into characters.  there is a method called getChars() in String class,plz use that and separate into characters so plz verify the String api for related questions 
Java String
Java String       In this section, you will learn about the java string. Java String is a set... to a string literal in the object stream. The Java String object contains a sequence
string - Java Beginners
string in java interview questions  What is string in java? Interview questions
String in Java - Java Beginners
]); } } } ---------------------------------------------------- I am sending simple code of String array. If you are beginner in java...String in Java  hiiiii i initialise a String array,str[] with a size... in advance   Hello Antony Insted Using String Array Use StringBuffer
searching from database
searching from database  how to search data from data base throug search...such as contact no./lastname /firstname should give whole information from database...   Please visit the following link: Servlet search
Java string buffer
Java string buffer  what is stringBuffer and StringBuilder
Searching an element - JSP-Servlet
Searching an element  Dear sir, sir i have an employee... in that i am doing a searching an element by empId and displaying a all... field for searching an element by the empId.and one submit button for submitting
Searching an element - JSP-Servlet
Searching an element  Dear sir, sir i have an employee table... doing a searching an element by empId and displaying a all the employee table... for searching an element by the empId.and one submit button for submitting this form.And
String immutable - Java Beginners
String immutable  Why is String immutable?  See here Why String is immutable in Java
How to convert into to String in Java?
How to convert into to String in Java?  Hi, How to convert into to String in Java? Thanks
capitalizing string in java
capitalizing string in java  How to capitalizing string in Java?   String s = "some string"; String capitol = Character.toString(s.charAt(0)).toUpperCase(); String newString = capitol + s.substring(1,x
How to Append String In Java?
How to Append String In Java?  How to write program in in Java for appending to a String? How to Append String In Java? What is the best way to do... the StringBuilder class. Check the example at Appending String in java. You can
converting string to double in java
converting string to double in java  Please post an example to converting string to double in java. Thanks!   Convert String to Double Tutorial
Java string buffer
Java string buffer  What is the basic difference between string and stringbuffer object
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Java String Datatype
Java String Datatype  Weather String in java is class or Datatype,if it's clss then How can i assign String str="hello";   String is a class found in the package java.lang.*. When we represent string in double quotes
Core Java String
Core Java String  Hi , Here my code Class Test { String s1 = "null"; String s2 = "null"; String s3 = s1+s2; } what is the out put
On string - Java Beginners
On string -Display reverse String using string reverse method in Java  I wanted to display reverse String using string.reverse() method in Java  Display reverse String using string.reverse()String Reverse Using
java programmming: string manipulation
java programmming: string manipulation  WAP to accept a string from...' occurring in it   Here is a java example that reads a string from the command prompt and find the frequency of the character e in the input string
String - Java Interview Questions
Java String array declaration and initialization  I am looking for an example of java string array declaration and initialization  Hipublic class ImmutableCart { private final List items; public ImmutableCart(List
How To Append String In Java
How To Append String In Java In this section we will read about how to append String in Java. Here we will see the solution of this question through a simple example. There are various ways to append String in Java. Below, we
String Mirror in Java
String Mirror in Java  how to get a mirror image of(string) a given string in java   Hello Friend, Try this: import java.util.*; class StringMirror{ public static void main(String []args){ String str="hello
java string multiplication
java string multiplication  Is there any simple method of string multiplication in java ..?   public class StringMultiplication { public static void main(String[] args) { String number1 = "17"; String number2
Core Java -String
Core Java -String  Write a program to print "Ranjan pintu am i". the given string is i am pintu ranjan. here there is a condition, we can't use split() method, using loop only
java string comparison example
java string comparison example  how to use equals method in String... static void main(String [] args){ String str="Rose"; String str1... using equals() method. In the above example, we have declared two string
 

 

 

DMCA.com