SPRING | Collections를 사용하여 리스트를 정렬하기
Collection을 활용해서 정렬을 할 수 있습니다. List product = new ArrayList(); 이런 List가 있는데 이 안에는 code 와 sell_price가 들어있었습니다. sell_price로 정렬을 하는 방법을 찾아봤습니다. Collections.sort(product, new Comparator() { @Override public int compare(Product o1, Product o2) { if(o1.getSellPrice() o2.getSellPrice()){ return 1; } return 0; } }); 이렇게 하면 두 값을 비교해서 정렬을 해줍니다.
개발일기
2023. 1. 30. 17:40