samedi 10 février 2018

Why is my if statement never executing the code under it? [duplicate]

This question already has an answer here:

Ok so I am writing a program to go through a list of author objects, count how many times one occurs, remove the duplicates, then add however many times the author object occurred in the array to an attribute of the object. My question is why is my if statement in here not working? I am expecting authors to have 3 elements but it ends up having 6 which is the amount the authors array started with. I know the statement should be evaluating and executing because I purposefully added duplicates. Thanks for the help!

public static ArrayList<WikipediaAuthor> addRevisionsAuthor(ArrayList<WikipediaRevision> wikiRevisions) {
    ArrayList<WikipediaAuthor> authors = new ArrayList<WikipediaAuthor>();
    for (int x = 0; x < wikiRevisions.size(); x++) {
     `enter code here`   boolean added = true;
        WikipediaAuthor temp = new WikipediaAuthor(wikiRevisions.get(x).getName());
        authors.add(temp);
    }
    for (int x = 0; x < authors.size(); x++) {
        String temp1 = authors.get(x).getName();
        for (int y = x+1; y < authors.size(); y++) {
            String temp2 = authors.get(x).getName();
            if (authors.get(x).getName() == authors.get(y).getName()){
                System.out.println("hit");
                authors.get(x).modifyRevisions();
                authors.remove(y);
                }
            }
        }
    return authors;
}

Aucun commentaire:

Enregistrer un commentaire