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 of an artist and output that artist's position in the charts or a message saying that they are not present.

You should choose the most appropriate search method introduced in the lecture and modify it so that it handles strings, rather than integers.

View Answers

December 9, 2011 at 12:21 PM

import java.util.*;
class SearchingAndSorting 
{
    public static void main(String[] args) 
    {
        String names[]={"AAAA","DDDD","FFFF","ZZZZ","KKKKK","PPPP"};
        ArrayList<String> list=new ArrayList<String>();
        for(int i=0;i<names.length;i++){
            list.add(names[i]);
        }
        Scanner input=new Scanner(System.in);
        System.out.print("Enter Name: ");
        String name=input.nextLine();

        int index;
        if(list.contains(name)){
            index=list.indexOf(name);
            System.out.println("Position: "+(index+1));
        }
        else{
            System.out.println("Artist is not present");
        }


    }
}









Related Tutorials/Questions & Answers:
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
Sorting and Searching
Sorting and Searching  Hi i would really be thankful if someone could help me with this A program is required to ask users to rate the Java...) { Scanner input = new Scanner(System.in); System.out.print("Rate Java(0-10
Advertisements
Insertion, sorting and searching in array
to perform searching and sorting in array. In the java code given below we have...; } Insertion, sorting and searching in array   ...("\nArray elements after sorting", array); // Search for element
Sorting in Java
Sorting in Java  Sorting in Java
Java sorting
Java sorting  can somebody help me know how java sorts? means which... the following links: Java bubble sort Java Heap Sort Java Insertion Sort Java Merge Sort Java Selection Sort Java Quick Sort   hello
Bubble Sorting in Java
Bubble Sorting in Java  Hi, What is Bubble Sorting? Guide me where to learn Bubble Sorting in Java? Thanks   Hi, Check the tutorial at Bubble Sorting in Java. Thanks
Sorting
Sorting  can any help me know which sorting algorithm java uses for sorting collection and arrays
Java Sorting
Java Sorting  Could somebody help me with this question. Implement a program to process votes for 5 candidates in a talent contest. The program should use a String array to hold the names of the 5 candidates and an integer
Java String searching.
Java String searching.  How to search a string in given String array?   import java.util.Scanner; public class StringSearch { public... and for searching we used userCity.equalsIgnoreCase(city[i
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
sorting
sorting   write a program to arrange sorting in rows,column and diagonal
sorting array in java
sorting array in java  How to sort array in Java or JavaScript?   JavaScript Sorting array tutorial   Java Sort array of strings import java.util.*; class ArrayExample{ public static void main(String
sorting
sorting  write to a program to arrange the sorting in rows, column and digonal
merge sorting in arrays - Java Beginners
merge sorting in arrays  Write a program to insert string or characters to an array and apply merge sorting on this array  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners
java array sorting manual way
java array sorting manual way  Hi, Anyone has any sample code on how to sort a array manually without using the inbuild sorting algorithm? Thanks
sorting
sorting  how to do sorting without using bubble sort,selection sort
java sorting codes - Java Beginners
java sorting codes  I want javasorting codes. please be kind enogh... the following link: http://www.roseindia.net/java/beginners/arrayexamples/ Here you will get various sorting algorithms. Hope that it will be helpful for you
Sorting algorithms - Java Beginners
Sorting algorithms  I'v being given an assignment and I still couldn't find a proper answer for the following questions.Can anyone pls pls help me wi it? 1)Compare and contrast efficiencies of Shell,Quick,Heap and Radix sort
Sorting in java - Java Beginners
Sorting in java  Hello.. I want you to help me with this question.. 1. A statistics company wants to keep information of families. The information of a family is the family name, the number of members and first name of each
SORTING - Java Interview Questions
("Items after sorting are ="+list); } } Thanks
sorting - Java Beginners
; Easy Sorting: For all the values in the array A, find the largest and store
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
Array sorting - Java Beginners
Array sorting   Hello All. I need to sort one array based on the arrangement of another array. I fetch two arrays from somewhere and they are related. For example, String type[] = {"X","T","3","R","9"}; String
Java Hashmap Sorting - Java Beginners
Java Hashmap Sorting   I have a sorting issue with a Hashmap. My constraint is that I MUST use the Hashmap and work with existing code. I do..., it loses the original alphabetical sorting done by the database. So, my problem
Comparison between the types of sorting in java
Comparison between the types of sorting in java  welcome all i wanna program in java compare between selection,insertion,bubble,merge,quick sort... of sorting. please help me thanks all
sorting student record - Java Beginners
sorting student record  Program in java for inserting, recording, deleting, editing and searching student details   can u explain about recording ? u want to store value in database or in file or opertinng run time
NAME SORTING. . .anyone? - Java Beginners
NAME SORTING. . .anyone?  how can I sort names without using the 'name.sort' method? please help. . .anyone? the program should sort the first three(3) letters of the names tnx java masters out there!! (^_^) cVm  Hi
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
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
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
ARRAYS SORTING - Java Interview Questions
ARRAYS SORTING  How To Sort An Array With Out Using Sort Method ?I Want Code?  Hi, Here is the code in java. You can find both Ascending and Descending order code. Ascending order is commented. public class
sorting an array of string with duplicate values - Java Beginners
sorting an array of string  Example to sort array string
searching technique
searching technique  Hi, i need any searching technique in java to search the data and give the all possible data by links
sorting an array of string with duplicate values - Java Beginners
sorting an array of string with duplicate values  I have a sort method which sorts an array of strings. But if there are duplicates in the array it would not sort properly
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
Sorting String arrays in java - Java Beginners
Sorting String arrays in java  I have to make an interface that creates an array of unknown size, resizes the array when needed, and sorts the array... not think that my sorting thusfar is correct. Can anyone help? Please help
searching books
searching books  how to write a code for searching books in a library through jsp
group by sorting
group by sorting  group by sorting of data in SQL
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 string
searching string   how to write a program for searching a string   Hi Friend, Try this: import java.util.*; class SearchString{ public static void main(String[] args){ Scanner input=new Scanner(System.in
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
searching the string in a paragraph?
searching the string in a paragraph?  how to search a string in a paragraph and display the corresponding line number and position of a string in java
Sorting an ArrayList
Sorting an ArrayList  print("code sample");Hello All, I am working on a program for school and I am having trouble with sorting my list... really new at Java...This is only the second program I am writing for school
linear sorting
linear sorting  what is linear sorting? can any send me an example   Hi Friend, Try this: import java.util.*; class ArraySort{ public...("After Sorting: "); for(int i=0;i<arr.length;i++){ System.out.println
sorting and storing data
sorting and storing data   sorting and storing data in UITableView

Ads