Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static String getHost(String url) {
        if (url == null || "".equals(url.trim()))
            return null;

        Pattern p = Pattern.compile("(?<=//|)((\\w)+\\.)+\\w+");
        Matcher matcher = p.matcher(url);
        if (matcher.find())
            return matcher.group();
        else
            return null;
    }

    public static boolean equals(String str1, String str2) {
        return str1 != null && str2 != null && str1.equals(str2);
    }

    public static boolean equals(String str1, String str2, boolean ignoreCase) {
        if (str1 != null && str2 != null) {
            if (ignoreCase) {
                return str1.equalsIgnoreCase(str2);
            } else {
                return str1.equals(str2);
            }
        } else {
            return str1 == null && str2 == null;
        }
    }

    public static boolean equalsIgnoreCase(String str1, String str2) {
        return str1 != null && str2 != null && str1.equalsIgnoreCase(str2);
    }
}