Firstly... I am a new in Java...
I have a music dictionary that use an arreylist to store the terms and definition
The user use the terminal to interact with this dictionary.

private void addTerms () 
        addTerm("Anathema","Atmosheric metal band from Liverpool, UK."

Because, I would like to make it more sophisticated, if someone write not a band but a letter eg A or B or C then the dictionary to give him as feedback all the bands that their first letter is A or B or C.

I am trying to do this with substring(0,1).

if (band.substring(0,1) = bandExists(band).substring(0,1)
System.out.println(i dont know what to print!!!!)

and another question...

if it works, and prints the bans names that their first letter is "A"

1. Agathodemon
2. Anathema
3. Annihilator

how possible is to write a number eg 3 and to print out now the definition of the band?

6 Years
Discussion Span
Last Post by masijade

You should probably create a class to represent a band that has a name and a description. Then you can use substring on the name part, and you should be comparing the substring to the user input. For example, say the user input is in a string called answer. Then you could compare like this:

if (band.getName().substring(0, 1).equals(answer))

In order to get numbers to print for your output, you need a variable to keep track of how many names you have output so far. For example, say your ArrayList is called musicCollection. The the loop might look something like this:

int counter = 1;
for (Band band : musicCollection) {
   if (band.getName().substring(0, 1).equals(answer)) {
      System.out.println(counter + ". " + band.getName());
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.