I work in Java on a project that requires me to make some โcontainerโ classes if you want. Here is a simple version:
public class Pair{ Object KEY; Object VALUE; public Pair(Object k, Object v) { KEY = k; VALUE = v; } public Object getKey() { return KEY; } public Object getValue() { return VALUE; } }
(Note that this is greatly simplified, and I use the correct set / get methods in the final version.)
My question is:
When calling the println method with the ArrayList parameter as a parameter, for example:
ArrayList<String> arr = new ArrayList<String>(); arr.add("one"); arr.add("two"); System.out.println(arr);
Java automatically knows how to correctly print each "node" or ArrayList element.
Is there a way to write a method that allows the println rule to correctly print my Pair class?
source share