문제

나는 다음과 같은 트리맵:

TreeMap<Integer, Double> map;

두 값은 고유하지 않습니다.

내가 반복을 통해 지도를 사용하여 정수 키와 기능 firstEntry()및 higherEntry()를 수정할 수 두 값이 있습니다.

지금 내가 목록을 원하는 값의 쌍을 내림차순으로 두 값이 있습니다.는 가장 좋은 방법은 무엇입니까?

그 정수 키를 나에게 중요하기 때문에 두 가지 고유가 있을 수 없는 두 키입니다.

업데이트:더 설명 그것은 고전적인 문제입니다.말할 수 있습 rollnos 학생의 열쇠와 자신의 비율입니다.지금 종류 백분율에 의하여 그리고 우리는 말할 수 있어야의 비율이 그것입니다.그러므로 내가 필요한 정수 열쇠이다.

도움이 되었습니까?

해결책

를 구축할 수 있습니다 TreeSet, 을 보장하는 삽입기:

@Test
public void treeMapSortedByValue() {
    // given the following map:
    TreeMap<Integer, Double> map = new TreeMap<Integer, Double>();
    map.put(2, Math.E);
    map.put(1, Math.PI);
    map.put(3, 42.0);

    // build a TreeSet of entries
    Set<Map.Entry<Integer, Double>> sortedEntries = new TreeSet<Map.Entry<Integer, Double>>(new DoubleComparator());
    sortedEntries.addAll(map.entrySet());

    // optionally you can build a List<Double> with the sorted 
    List<Double> doubles = new LinkedList<Double>();
    for (Map.Entry<Integer, Double> entry : sortedEntries) {
        doubles.add(entry.getValue());
    }
}

이것은 당신에게 제공: [2.718281828459045, 3.141592653589793, 42.0] (nb: [Math.E, Math.PI, Math.UNIVERSAL_ANSWER] :-).

PS

Comparator:

class DoubleComparator implements Comparator<Map.Entry<Integer, Double>> {

    @Override
    public int compare(Entry<Integer, Double> o1, Entry<Integer, Double> o2) {
        return Double.compare(o1.getValue(), o2.getValue());
    }
}

다른 팁

CSS 전용 방식의 경우 콘텐츠 편집기 웹 파트 내에 다음 CSS를 추가하거나 사용자 지정 CSS에 추가하십시오.필요에 따라 <style> 태그를 제거하십시오.

<style type="text/css">

  /*  tile row height */
  div.ms-promlink-body {
    height: 100px;
  }

  /*  tile dimensions, including inter-tile margin */
  div.ms-tileview-tile-root {
    width: 110px !important;
    height: 110px !important;
  }

  /*  tile and title( + description) overlay dimensions */
  div.ms-tileview-tile-content, div.ms-tileview-tile-detailsBox {
    width: 100px !important;
    height: 100px !important;
  }

  /*  tile background image dimensions */
  div.ms-tileview-tile-content > a > img {
    width: 100% !important;
    height: 100% !important;
  }

  /*  title and description text  */
  ul.ms-tileview-tile-detailsListMedium {
    height: 100px;
    padding: 4px 7px 7px;
    font-size: 11px;
    line-height: 14px;
  }

  /*  description text class  */
  li.ms-tileview-tile-descriptionMedium {
    padding-top: 10px;
    font-size: 11px;
  }

  /*  title text when description not shown  */
  div.ms-tileview-tile-titleTextMediumCollapsed {
    background-color: rgba(0, 0, 0, 0.6);
    width: 86px;
    height: 29px;
    position: absolute;
    top: -33px;
    left: 0px;
    padding: 4px 7px 0px;
    font-size: 11px;
    line-height: 13px;
  }

</style>
.

코드는 100x100의 타일 크기입니다.자신의 이미지를 위해 위의 코드는 트릭을 수행해야합니다.OOTB SharePoint 이미지 (기본 타일 세트 ( "사이트 공유", "마감일로 작업", ""사이트 공유 ", 등록하십시오.), 추가 변경 사항이 필요합니다.

What you can do is the following : use entrySet to iterate through the entries. Put them into a list. Sort the date with the right comparator then.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top