For your task, you do not need to operate with variable names, although this is possible with the help of reflection.
Reflection can break if you apply code obfuscation, which changes the variable names. You need another way.
You have a data model with currency and price values. So you need to create a class for storing this data with comparators and equals&hashCode something like this:
public class MyData { public String name; public BigInteger value; public MyData(String name, BigInteger value) { this.name = name; this.value = value; } public static Comparator<MyData> COMPARATOR_NAME = (o1, o2) -> o1.name.compareTo(o2.name); public static Comparator<MyData> COMPARATOR_VALUE = (o1, o2) -> o1.value.compareTo(o2.value); public int hashCode() { return name.hashCode() + value.hashCode(); } public boolean equals(Object other) { if (this === other) return true; if (getClass() != other.getClass()) return false; MyData otherData = (MyData) other; if (name.equals(otherData.name)) return false; if (value != otherData.value) return false; return true; } }
Now you can use this model in adapters and sort as you like by any field. And no reflection is necessary.