Reputation: 29
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 :)
Upvotes: 1
Views: 40
Reputation: 2683
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);
}
}
}
Upvotes: 1
Reputation: 6331
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);
Upvotes: 0