I have a hashmap of the following type
HashMap> map=new HashMap>();
<
You can use like this(Though the random number generator logic is not upto the mark)
public class WorkSheet {
HashMap> map = new HashMap>();
public static void main(String args[]) {
WorkSheet test = new WorkSheet();
test.inputData("mango", 5);
test.inputData("apple", 2);
test.inputData("grapes", 2);
test.inputData("peach", 3);
test.displayData();
}
public void displayData(){
for (Entry> entry : map.entrySet()) {
System.out.print(entry.getKey()+" | ");
for(int fruitNo : entry.getValue()){
System.out.print(fruitNo+" ");
}
System.out.println();
}
}
public void inputData(String name ,int number) {
Random rndData = new Random();
ArrayList fruit = new ArrayList();
for(int i=0 ; i
grapes | 7 5
apple | 9 5
peach | 5 5 8
mango | 4 7 1 5 5