2016-11-04 2 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 메서드는 대소 문자와 발생한 횟수를 반환합니다.foreach 루프를 사용하여 임계 값보다 큰 문자열을 출력 하시겠습니까?

+0

또한 프로그래밍 언어 이름으로 태그를 지정해야합니다. – Bobby

+0

'counted' 맵을 반복하고 (# entrySet에'Iterator'를 사용하여) 임계 값보다 작은 값을 가진 항목을 제거한 다음, print map – 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

관련 문제