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



Home Answers Viewqa Java-Beginners Java Sorting and Searching

Have Programming Question? Ask it here!
 
 
 


David Ferguson
Java Sorting and Searching
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


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.


Advertisement
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   ... after sorting", array); // Search for element in specified array
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
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
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
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
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  can any help me know which sorting algorithm java uses for sorting collection and arrays
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 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
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
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
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 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
sorting   write a program to arrange sorting in rows,column and diagonal
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
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
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
sorting
sorting  write to a program to arrange the sorting in rows, column and digonal
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
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
sorting
sorting  how to do sorting without using bubble sort,selection sort
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
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
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  Example to sort array string
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
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
group by sorting
group by sorting  group by sorting of data in SQL
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
Sorting Array List in Java
Sorting Array List in Java In this example you will learn about sorting array list in java using an example. By default array list are sorted as the element are inserted into the list. In Java ArrayList extends AbstractList implements
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
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 Program
Sorting Program  To sort 10items in alphabetical order   Arrays.sort(name of ur array)   import java.util.*; class ArrayExample{ public static void main(String[] args) { String array[]=new
 

 

 

DMCA.com