Java examples for java.lang:String Algorithm
the rate list Known Word occur in list Word.
//package com.java2s; import java.util.List; public class Main { public static void main(String[] argv) throws Exception { List listWord = java.util.Arrays.asList("asdf", "java2s.com"); List listKnowWord = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(getKnowWordRate(listWord, listKnowWord)); }/*from w ww. ja va 2 s. c o m*/ /** * 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; } }