Ewa Kania
Ewa Kania

Reputation: 51

Cannot import Map.Entry

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

Answers (3)

user840718
user840718

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

Ian Roberts
Ian Roberts

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

Nikhil Talreja
Nikhil Talreja

Reputation: 2774

for(Map.Entry<String, Integer> entry : someMap.entrySet())

works with import java.util.Map import alone.

Upvotes: 5

Related Questions