# Sorting ArrayList

**URL:** <https://discourse.processing.org/t/sorting-arraylist/5083>\
**Category:** Coding Questions\
**Created:** [November 1, 2018, 12:20pm UTC](https://discourse.processing.org/t/sorting-arraylist/5083 "2018-11-01T12:20:08Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 1, 2018, 12:25pm UTC](https://discourse.processing.org/t/sorting-arraylist/5083/2 "2018-11-01T12:25:24Z")

</div>

> [@Sort PVector array by distance](https://discourse.processing.org/t/sort-pvector-array-by-distance/4737/3):
>
> Use the sketch from this link below as a model: nerd_face[Forum.Processing.org/two/discussion/19469/sort-a-pvector-array#Item\_9](http://Forum.Processing.org/two/discussion/19469/sort-a-pvector-array#Item_9) But change its Comparator::compare() to use dist() instead. stuck_out_tongue

> [@Accessing functions from Java Generics](https://discourse.processing.org/t/accessing-functions-from-java-generics/3391/2):
>
> If you intend to sort() your arrays or collections by some numerical value, you can make your classes implements DoubleSupplier: import java.util.function.DoubleSupplier; class SomeClass implements DoubleSupplier { float x; @Override double getAsDouble() { return x; } } And use the Comparator below in order to sort() by ascending numerical order: import java.util.Comparator; import java.util.function.DoubleSupplier; import java.util.Arrays; import java.util.Collections; static f…

> [@Accessing functions from Java Generics](https://discourse.processing.org/t/accessing-functions-from-java-generics/3391/9):
>
> Even If we had 2 or more classes w/ the exactly same code, Java would still “see” them as different from each: void setup() { MyVec vec1 = new MyVec(); MyVecTwin vec2 = new MyVecTwin(); println(MyVec.class.isInstance(vec1)); // true println(MyVec.class.isInstance(vec2)); // false exit(); } class MyVec { float x = random(-100, 100), y = random(-100, 100), z; @Override String toString() { return "[" + x + ", " + y + ", " + z + "]"; } } class MyVecTwin { // exactly same…

---

_[View the full topic](https://discourse.processing.org/t/sorting-arraylist/5083)._
