Java tutorial
//package com.java2s; import java.util.List; public class Main { /** * @param string - this is the current value, e.g. itemNo * @param list - list of strings, e.g. list of products * @return string value * method = getPreviousInList * Send in value and a list of values, returns the previous value from the list. * returns null if the value sent in is the first value in the list. * */ public static String getPreviousInList(String string, List list) { String previousString = null; if (list != null) { int i = list.indexOf(string); if (i == 0 || list.size() < 2) {//this is the first value in the list return previousString; } else { previousString = list.get(i - 1).toString(); } } return previousString; } }