Java examples for java.lang:String Algorithm
get Known Word Rate
//package com.java2s; import java.util.List; public class Main { public static void main(String[] argv) { List listWord = java.util.Arrays.asList("asdf", "java2s.com"); List listKnowWord = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(getKnowWordRate(listWord, listKnowWord)); }/* www . j ava 2 s. c om*/ /** * the rate listKnowWord occur in listWord. * @param listWord * @param listKnowWord * @return rate knew word / all word */ public static double getKnowWordRate(List<String> listWord, List<String> listKnowWord) { double rate = 0; int noOfKnowWord = 0; if (listWord.size() == 0) { return 0; } if (listKnowWord.size() == 0) { return 1; } for (String word : listWord) { if (listKnowWord.contains(word)) { noOfKnowWord++; } } rate = (double) noOfKnowWord / listWord.size(); return rate; } }