package test import java util Arrays import java util HashMap import j

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Created by GrabetsB on 24.02.2015.
*/
public class DatabaseBook
{
public static void request(HashMap<String,String[]> map, String book ){
Iterator<Map.Entry<String,String[]>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, String[]> pair = iterator.next();
String key = pair.getKey();
String[] value = pair.getValue();
if (key.equals(book)){
System.out.println("Book: "+key.toUpperCase()+" Authors: "+ Arrays.toString(value).toUpperCase());
break;
}
}
}
public static void main(String[] args)
{
HashMap<String, String[]> db = new HashMap<String, String[]>();
db.put("Book1",new String[]{"Author1","Author2"});
db.put("Book2",new String[]{"Author3","Author1"});
db.put("Book3",new String[]{"Author2","Author3"});
db.put("Book4",new String[]{"Author4","Author1"});
request(db, "Book3");
}
}