title: Find and update an element in a Java Queue
body: <p>Trying to work on small use case where i have to add string of websites in a queue. if the site repeats then i have to update the numberofVisits+1. Else i would add that object into the queue. Something wrong with updateCount code. Please let me know</p>
  
  <p>here is the code snippet. I am unable to move forward on this.</p>
  
  <pre><code>public CLassName(String url, int numVisits) {
          this.url = url;
          this.numVisits = numVisits;
  }
      public int getNumVisits() {
          return this.numVisits;
      }
  
      public String getUrl() {
          return this.url;
      }
      public void setNumVisits(int updatedNumVisits) {
          this.numVisits = updatedNumVisits;
      }
  
  private static Queue&lt;ClassName&gt; sites = new LinkedList&lt;ClassName&gt;();
  
      // Method to find the website in the queue and increment the visited count by 1, adding new node in case website is not found
  
  public static void update(String url) {
  
  //code should go in here. // THis is wrong code
  
  if (sites.isEmpty()) sites.add(new ClassName(url,1));
           while(!sites.isEmpty()) {
               String tmpUrl = sites.peek().getUrl();
               int numVisits = sites.peek().getNumVisits();
              if(tmpUrl!=null &amp;&amp; tmpUrl.equalsIgnoreCase(url)) {
                  sites.add(new ClassName(tmpUrl,numVisits+1));
              } else if(tmpUrl!=null){
                  sites.add(new ClassName(tmpUrl,numVisits));
              } else {
                  sites.add(new ClassName(url,1));
              }
           }
  
  }
  public static void main(String[] args) {
          String[] visitedSites = { "www.google.co.in", "www.google.co.in", "www.facebook.com", "www.upgrad.com", "www.google.co.in", "www.youtube.com",
                  "www.facebook.com", "www.facebook.com", "www.google.co.in", "www.microsoft.com", "www.9gag.com", "www.netflix.com",
                  "www.netflix.com", "www.9gag.com", "www.microsoft.com", "www.amazon.com", "www.amazon.com", "www.uber.com", "www.amazon.com",
                  "www.microsoft.com" };
  
          for (String url : visitedSites) {
              update(url);
          }
  </code></pre>