And now for an answer (kind of)
public class MyThingie { TreeMap<Integer, String> data = new TreeMap<Integer, String>(); 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); } } }
and now for a more interesting answer:
public class BiggestFinder { public void showBiggester(Object o) throws Exception { TreeMap<Integer, String> data = new TreeMap<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()); } }
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".