What does colon mean in Java?

What does a colon mean in Java? I have this:

public static List<String> findAllAnagrams(List<String> words) {
    List<String> result = new LinkedList<String>();
    for(String i : words){
        for (String j : words){
            if (result.contains(i)) {
                break;
            }
            else if (i == j) {

            } else {
                if (areAnagrams(i,j)){
                    result.add(i);
                    System.out.println(result);
                }
            }
        }
    }          
    return result;
}

Solution

This means one thing, it's an enhanced cycle

for (String i: words)

It means the same thing

for (int i = 0; i < words.length; i++) {
    //
}

Joshua Bloch said in item 46 of his valuable Java:

for (Element e : elements) {
    doSomething(e);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>