2016-11-04 6 views
-2
public Set<String> filterAlleles (int threshold) { 
    Set<String> filtered = new HashSet<String>(); 
    Map<String, Integer> counted = this.countAlleles(); 
    for (String allele : _alleles){ 

私は以前にcountAllelesメソッドを書いていたので、このメソッド宣言で指示通りに使用しています。 countAllelesメソッドは、Alleleと発生した回数を返します。foreachループを使用して、しきい値以上の文字列を出力しますか?

+0

これには、プログラミング言語の名前も付いています。 – Bobby

+0

'counted'マップを反復し、(#entrySet'の' Iterator'を使って)閾値より小さい値を持つエントリを削除してから、 – Rogue

答えて

0

forループを使用して> 7のデータをフィルタリングして印刷するサンプルコードを次に示します。あなたがコードをほとんど提供しなかったので、うまくいけば助けてくれるサンプルを添付します。

public static void main(String[] args) { 
    Map<String,Integer> counted = new HashMap<>(); 
    counted.put("foo", 3); 
    counted.put("bar", 10); 
    counted.put("baz", 6); 
    counted.put("goo", 11); 

    counted.entrySet().stream()    // Stream the entry set 
      .filter(e->e.getValue() >= 7)  // Filter on >= threshold 
      .map(Map.Entry::getKey)   // Get the key since it's the name we are looking for 
      .forEach(System.out::println);  // Print the list 
} 
+0

のリストを収集するのは何ですか?この場合はノーオペレーションのようです。 – Tom

+0

彼らは望む場合には、さらに弦を操作したいが、それ以外の場合は、収集を省略することができる。それは、質問がそのようにほとんど情報を提供しなかったので、一例です。 – AlexC

関連する問題