Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

public class Main {
    private static String getCommonSubStringFromList(ArrayList<String> list) {
        if (list != null && list.size() > 0) {
            String[] tokens = ((String) list.get(0)).split("/");
            String path = null;
            String temp = "";

            for (int i = 0; i < tokens.length; ++i) {
                if (!tokens[i].trim().isEmpty()) {
                    temp = temp + "/" + tokens[i];
                    if (isValidSubString(list, temp)) {
                        path = temp;
                    }
                }
            }

            return path;
        } else {
            return null;
        }
    }

    private static boolean isValidSubString(ArrayList<String> list, String token) {
        if (list != null) {
            for (int i = 0; i < list.size(); ++i) {
                if (!((String) list.get(i)).startsWith(token)) {
                    return false;
                }
            }

            return true;
        } else {
            return false;
        }
    }
}