Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>And now for an answer (kind of)</p> <pre><code>public class MyThingie { TreeMap&lt;Integer, String&gt; data = new TreeMap&lt;Integer, String&gt;(); public void doIt() { ... insertElement("politics_counter", politics_counter); insertElement("economics_counter", economics_counter); insertElement("foreign_counter", foreign_counter); insertElement("sport_counter", sport_counter); insertElement("weather_counter", weather_counter); System.out.println("Highest variable is "+data.lastEntry().getValue()); } public void insertElement(String name, Integer i) { if (data.get(i) == null) { System.out.println("Element "+name+" has the name value as "+data.get(i)); } else { data.put(name,i); } } } </code></pre> <p>and now for a more interesting answer:</p> <pre><code>public class BiggestFinder { public void showBiggester(Object o) throws Exception { TreeMap&lt;Integer, String&gt; data = new TreeMap&lt;Integer, String)(); for (Field f : o.getDeclaredFields()) { Object v = f.getValue(o); if (v instanceof Integer) { if (data.get(v)!=null) { System.out.println("Value for "+f.getName()+" is the same as "+data.get(v)); } else { data.put((Integer)f.getValue(o), f.getName()); } } } System.out.println("Largest is "+data.lastEntry().getValue()); } } </code></pre> <p>which will interrogate an object and show the largest field, given that the object has members that are all Integers and that are all accessible to this method. There's a way to fudge that and improve it to make it more "robust".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload