1

Ok, so I have a array

String[] sound = new String[2]
sound[0] = nameSound;
sound[1] = routeSound;

and this Array is in an Array

String[] Sounds[]= new String[1][]; 

Sounds[0]=sound;

I just made an Array, but I will have a lot of arrays

And if the users write nameSound "name", It has to be compared to the nameSound of every vector called sound, when it is found, I want something like

 System.out.print(nameSound);

Any ideas are appreciated :)

2 Answers 2

1

The simplest solution is to use just 2 for loops. But if the arrays are realy large you must find some more performance optimated way.

for(String[] sound : Sounds)
{
    for(String soundName : sound)
    {
        if(soundName.equals(searchString))
        {
             System.out.print(soundName);
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You could of course loop over all nested arrays, the code itself isn't hard. But aren't you actually looking for the functionality of a map where you store the name as key and route as value? Then you could easily find the routeSound by entering the nameSound, while you still have access to the data.

pseudocode:

Map<String, String> sounds = new HashMap<String, String)();
sounds.put(nameSound, routeSound);

String foundRouteSound = sounds.get(inputNameSound);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.