Java BigDecimal

  • + 0 comments
    Comparator<String> myComparator = (s1, s2) -> {
                if (s1 == null && s2 == null) return 0;
                if (s1 == null) return 1; // Push nulls to the end
                if (s2 == null) return -1; // Push nulls to the end
                BigDecimal bd1 = new BigDecimal(s1);
                BigDecimal bd2 = new BigDecimal(s2);
                return bd2.compareTo(bd1); // Sort in descending order based on numeric value
            };
            
            Arrays.sort(s,myComparator);