+ 2
If i don't use generics then why do i need to convert it into generics ?
Set set=map.entrySet();
10 Respuestas
+ 11
Sorry, I don't understand your question. What do you want to do?
+ 3
Set is a generic interface so if you use Set you use generic.
+ 2
Yes, a generic interface so every implementation is a generic class. Sorry for the mistake, I fixed it ;)
+ 2
You can:
https://code.sololearn.com/cpY85ql77YLX/?ref=app
But as Set is Iterable, it is better to use in enhanced for than use Iterator
+ 1
/Non-generic  
import java.util.*;  
public class MapExample1 {  
public static void main(String[] args) {  
    Map map=new HashMap();  
    //Adding elements to map  
    map.put(1,"Amit");  
    map.put(5,"Rahul");  
    map.put(2,"Jai");  
    map.put(6,"Amit");  
    //Traversing Map  
    Set set=map.entrySet();//Converting to Set so that we can traverse  
    Iterator itr=set.iterator();  
    while(itr.hasNext()){  
        //Converting to Map.Entry so that we can get key and value separately  
        Map.Entry entry=(Map.Entry)itr.next();  
        System.out.println(entry.getKey()+" "+entry.getValue());  
    }  
}  
}
+ 1
set is a interface
+ 1
public interface Set<E> extends Collection<E>
0
if we use generics then we don't need this line
0
what is generic interface ?
0
why we can't write ..Iterator i=map.entryset().iterator()



