public static Element testMethod(Object[] arr, String ... keys) { final Element e = DocumentHelper.createElement("Test"); for (int i = 0; i < arr.length; i++) { e.addAttribute(keys[i], arr[i].toString()); } return e; } public static void main(String[] args) { final Object[] arr = testQuery(); System.out.println(testMethod(arr, "foo", "bar", "moo", "zoo")); }