简体   繁体   中英

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() );
    }
    }

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

仅与import java.util.Map导入一起使用。

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.

for (Map.Entry<String, ProteinSequence> entry : a.entrySet();

should be

for (Map.Entry<String, ProteinSequence> entry : a.entrySet())

(closing parenthesis instead of semicolon).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM