Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static String getParentNameofPath(String path) {
        if (path.equals("/")) {
            return null;
        }
        if (path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        int index = path.lastIndexOf('/');
        if (path.length() == 1) {
            return path;
        }
        if (index == 0) {
            return "/";
        }
        return path.substring(0, index);
    }
}