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 

import java.util.List;

public class Main {

    public static double calcStrArrayListSimilarity(final List<String> strAList1, final List<String> strAList2) {
        int containsCount = 0;
        List<String> biggerList;
        List<String> smallerList;
        if (strAList1.size() < strAList2.size()) {
            biggerList = strAList2;
            smallerList = strAList1;
        } else if (strAList2.size() < strAList1.size()) {
            biggerList = strAList1;
            smallerList = strAList2;
        } else {
            biggerList = strAList1;
            smallerList = strAList2;
        }

        for (int i = 0; i < biggerList.size(); i++) {
            if (smallerList.contains(biggerList.get(i))) {
                containsCount++;
            }
        }

        return (double) containsCount / (double) smallerList.size();
    }
}