Instead, you can use Map, as shown below,
public Map<String, List<Date>> getBothDates() { List<Date> startDate = new ArrayList<Date>(); List<Date> endDate = new ArrayList<Date>(); Map<String, List<Date>> bothDates = new HashMap<String, List<Date>>(); bothDates.put("startDate", startDate); bothDates.put("endDate", endDate); return bothDates; }
To get both dates, a simple iteration of the map,
public void printBothDates() { Map<String, List<Date>> bothDates = getBothDates(); for(Entry<String, List<Date>> entry : bothDates.entrySet()) { if(StringUtils.equalsIgnoreCase("startDate", entry.getKey())) { for(Date d : entry.getValue()) { System.out.println("startDate---"+d); } } else if(StringUtils.equalsIgnoreCase("endDate", entry.getKey())) { for(Date d : entry.getValue()) { System.out.println("endDate---"+d); } } } }
source share