Java String Tokenize countCommonTokens(String string1, String string2)

Here you can find the source of countCommonTokens(String string1, String string2)

Description

count Common Tokens

License

Open Source License

Declaration

public static int countCommonTokens(String string1, String string2) 

Method Source Code

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static int countCommonTokens(String string1, String string2) {
        List<String> string1Tokens = new ArrayList<String>(Arrays.asList(string1.split("\\s+")));
        List<String> string2Tokens = new ArrayList<String>(Arrays.asList(string2.split("\\s+")));

        string1Tokens.retainAll(string2Tokens);
        return string1Tokens.size();
    }/*  w w w .j a v a2s.c  o m*/
}

Related

  1. conservativeTokenize(String text)
  2. escapedTokens(String s, char separator)
  3. extractTokens(String strStartToken, String strEndToken, String strExpression)
  4. extractTokens(String text, String delim)
  5. getAllTokens(final String string)