I am trying to display the values inside a HashMap which is of the type Object[]. I tried using toString/deepToString/asList but it still shows values in the form @60e1e567.
How can I display all the values?
public class Hotels {
public static void main(String[] args) {
Map<Integer,HotelInfo[]> hotel = new HashMap<Integer,HotelInfo[]>();
HotelInfo[] hinfo = new HotelInfo[10];
Integer key = new Integer(4);
Integer key1 = new Integer(5);
hinfo[0] = new HotelInfo();
hinfo[0].setHotelName("Mariott");
hinfo[0].setAddress("Gurgaon, near Huda City Center");
hinfo[1] = new HotelInfo();
hinfo[1].setHotelName("Hyatt");
hinfo[1].setAddress("New Delhi, near Airport");
hotel.put(key1, hinfo);
HotelInfo[] hinfo1 = new HotelInfo[10];
hinfo1[0] = new HotelInfo();
hinfo1[0].setHotelName("Grand");
hinfo1[0].setAddress("Delhi, near Huda City Center");
hinfo1[1] = new HotelInfo();
hinfo1[1].setHotelName("ITC");
hinfo1[1].setAddress("New Delhi, Nehru Place");
hotel.put(key, hinfo);
// TODO Auto-generated method stub
Iterator<Integer> keyIterator = hotel.keySet().iterator();
while(keyIterator.hasNext()){
Integer aKey = keyIterator.next();
HotelInfo[] aValue = hotel.get(aKey);
System.out.println("Key : " + aKey);
for(int i=0;i<aValue.length;i++)
{
System.out.println(Arrays.asList(aValue[i]));
}
}
//HotelInfo[] value1 = hotel.get(5);
//System.out.println(value1);
}
}
Aucun commentaire:
Enregistrer un commentaire