Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
        int i = list.indexOf(string);
        if (i == 0) {//this is the first value in the list
            System.out.println("this is the first item/string value in the list");
            return previousString;
        } else {
            previousString = list.get(i - 1).toString();
            System.out.println("what is previous item/string value= " + previousString);
        }
        return previousString;
    }
}