Q:

Method performance on Android

I have a method which should find a number of appearances of following words combination in array.
This method is re-written in Java from C# code i've made but it performs 50 times slower which makes me think i don't know much in Java internals to properly translate it.
This is the Java code:
 private Map<String, Long> WeightWords(Map<Sentence, Long> wordsWithWeight) {

    Map<String, Long> newWordsWithWeight = new HashMap();
    for (Map.Entry<Sentence, Long> item : wordsWithWeight.entrySet()) {

        String title = item.getKey().getTitle().toLowerCase();
        String[] split = title.split("-");
        String goodName = title.replace(split[0].trim() + " - ", "");
        if (title.contains(split[0].trim() + " - ")) {
            goodName = title.replace(split[0].trim() + " - ", "");
        } else if (title.contains(split[0].trim() + "- ")) {
            goodName = title.replace(split[0].trim() + "- ", "");
        }

        String[] strings = goodName.split(" ");
        String fullString = "";

        for (String s : strings) {
            if (!s.isEmpty()) {
                fullString += s + " ";
                String currentString = fullString.trim();
                Long counter = 0L;
                for (Map.Entry<Sentence, Long> wordEntry : wordsWithWeight.entrySet()) {
                    {
                        if (wordEntry.getKey().getTitle().toLowerCase().trim().contains(currentString))
                            counter++;
                    }
                }
                if (!newWordsWithWeight.containsKey(s))
                    newWordsWithWeight.put(s, counter);
            }
        }
    }
    return Utils.sortByValue(newWordsWithWeight);
}

A:

In your code you run n*n on same entry set named 'wordsWithWeight', and on each iteration you call toLowerCase() and trim(). You can  prepare your entry set before and then remove toLowerCase() and trim() calls on each iteration.This should  increase performance.

