This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am implementing module for a scenario where there is a Stock of Products which can be veiwed and added to shopping cart. I am using collections for this , just for sake of practicing Collections.
I am stuck at a point .
For implementation purpose , i have implemented following classes :
The issue is , MyHashMap extends HashMap and is actually implemented as an ArrayList of LinkedLists .In See i call view_all() , there on converting the mmap (instance of MyHashMap ) to Set
it seems there are no elemnets in the Set as is displayed from output of line 48(comment)
Integer i= Integer.valueOf(br.readLine());
/*case 1:new Buy().buy();
case 2:Stock.addStock();//////////NOTICE effect of sequencing in switch
case 3:new See().see();
//case 2:new Stock().addStock();
//default:System.out.println("No valid option chosen");
System.out.println("You would veiw relevant output shortly");
/*public class CustomColls
/*static*/ class MyHashMap extends HashMap /* ASK here if i add the generic types in the declaration , as done initially*/
//static LinkedList<Product> ArrayList=new ArrayList(LinkedList<Product>);
LinkedList<Product> temp= new LinkedList<Product>();
for(int i=0;i<9;i++)// initialising an array of empty ArrayLists
static int count=new int;
static ArrayList <LinkedList<Product>>al =new ArrayList<LinkedList<Product>>();
//static LinkedList<Product> array=new LinkedList;
static MyHashMap mmap=new MyHashMap();
/// see whether changes to the Map are reflected in its corresponding Collection
public void see() throws Exception
System.out.println("Select your options for the order in which you want to see the items\n 1:View all \n 2 :View price wise \n 3:view Brand wise\n 4:View latest arrivals");
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
arpita singh wrote:...it seems there are no elemnets in the Set as is displayed from output of line 48(comment)...
1. UseCodeTags (←click) - otherwise nobody will have the slightest clue where line 48 is. You can use the 'Edit' key to add them to your post.
2.Before you do, please read the DontWriteLongLines page. Some of yours are very long which, if you do add code tags, will make your thread very hard to read (and it's actually bad coding practice).
The rules here are:
80 characters max.
(the SSCCE (←click) page actually recommends 62)
And that includes string literals AND comments AND long method calls.
However, in answer to your main question, I would suggest having a look at the keySet() and values() methods of java.util.Map.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Joined: Oct 08, 2010
Basically , i need to know how to iterate over elements in a HashMap implemented as an ArrayList of LinkedLists ???
There is no such thing as a hash map implemented as an array list of linked lists.
You can iterate the lists, both sorts, very easily. If you actually have a Map, you can get sets of the “K”s and the “V”s, as Winston has already hinted.