SaveSnippets
Community
Pricing
Sign In
Get Started
Community
Public Snippets
2
Code shared by the SaveSnippets community — browse, copy, and get inspired.
All Languages
Bash
Go
HTML
Java
JavaScript
Kotlin
PHP
Python
Rust
SQL
TypeScript
#comparator
Clear
Tags
#php
#kotlin
#bash
#go
#sql
#rust
#typescript
#html
#java
#python
#files
#utils
#strings
#http
#concurrency
#async
#json
#arrays
#security
#types
#crypto
#database
#dates
#format
Java
Sorting with Comparator
`Comparator.comparing`, `thenComparing`, and `reversed()` chain into expressive multi-field sorts. Way cleaner than the old Comparable spaghetti.
#java
#collections
#sort
#comparator
Kotlin
Sorting Collections
`sortedBy { ... }` returns a sorted copy. `sortedWith(compareBy { ... })` chains tie-breakers cleanly. Avoid `sortBy` (in-place) on read-only lists.
#kotlin
#collections
#sort
#comparator