Reputation: 51
I have problems with import Map.Entry. Even though I have import import java.util.Map.Entry - there is an error : "The import java.util.Map.Entry cannot be resolved". And entrySet() method doesnot work. what is the problem? (I use jre8)
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.biojava3.core.sequence.ProteinSequence;
import org.biojava3.core.sequence.io.FastaReaderHelper;
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
LinkedHashMap<String, ProteinSequence> a = FastaReaderHelper.readFastaProteinSequence(new File("A2RTH4.fasta"));
for (Map.Entry<String, ProteinSequence> entry : a.entrySet(); //entrySet A map entry (key-value pair).
{
System.out.println( entry.getValue().getOriginalHeader() + "=" + entry.getValue().getSequenceAsString() );
}
}
}
Upvotes: 2
Views: 21277
Reputation: 1611
import java.util.Map
is enough
Try this code, should be work:
public static void main(String[] args) throws Exception {
LinkedHashMap<String, ProteinSequence> a = FastaReaderHelper.readFastaProteinSequence(new File("A2RTH4.fasta"));
Set entrySet = a.entrySet();
Iterator it = entrySet.iterator();
// Iterate through LinkedHashMap entries
System.out.println("LinkedHashMap entries : ");
while(it.hasNext())
System.out.println(it.next());
}
}
Instead of foreach, try an Iterator to iterate over a LinkedHashMap data structure.
Upvotes: 0
Reputation: 122364
for (Map.Entry<String, ProteinSequence> entry : a.entrySet();
should be
for (Map.Entry<String, ProteinSequence> entry : a.entrySet())
(closing parenthesis instead of semicolon).
Upvotes: 0
Reputation: 2774
for(Map.Entry<String, Integer> entry : someMap.entrySet())
works with import java.util.Map
import alone.
Upvotes: 5