我在导入Map.Entry时遇到问题。即使我有import import java.util.Map.Entry -也有一个错误:"The import java.util.Map.Entry cannot be resolved“。并且entrySet()方法不起作用。有什么问题吗?(我使用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() );
}
}
}发布于 2014-06-24 19:09:04
for(Map.Entry<String, Integer> entry : someMap.entrySet())仅适用于import java.util.Map导入。
发布于 2014-06-24 19:05:35
import java.util.Map就足够了
尝试这段代码,应该是有效的:
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());
}
}尝试使用迭代器遍历LinkedHashMap数据结构,而不是foreach。
发布于 2014-06-24 19:29:08
for (Map.Entry<String, ProteinSequence> entry : a.entrySet();应该是
for (Map.Entry<String, ProteinSequence> entry : a.entrySet())(结束括号而不是分号)。
https://stackoverflow.com/questions/24384948
复制相似问题