title: Fastest way to search a HashMap and mark places with the same name?
body: <p>My program has a search function where the user enters the name of a place that gets visible and marked on a map (if the place exists). I'm trying to find the fastest way to search a HashMap for places with the same name, mark them/make them visible and finally add all the marked places to an ArrayList. At the moment, about 2000 closely located places takes about 30 seconds to appear on the map as mentioned, and I've heard that operations such as these are supposed to go much faster. I'm guessing that my for loop is what's slowing things down. Is there a faster way to do this than below?</p>
  
  <pre><code>private Map&lt;String, List&lt;Place&gt;&gt; perName = new HashMap&lt;&gt;();
  
  List&lt;Place&gt; sameName = perName.get(name);
                  for (Place p : sameName) {
                      p.setVisible(true);
                      p.setMarked(true);
                  }
                  markedPlace.addAll(sameName);
  </code></pre>
  
  <p>Edit: Here are parts of the Place-class, such as the setMarked()-method (setVisible just shows the graphic components):</p>
  
  <pre><code>private boolean isMarked = false;
      private boolean isShown = false;
      private int[] xs = { 0, 20, 40 };
      private int[] ys = { 0, 40, 0 };
  
      protected Place(String name, Position position, String category) {
          setBounds(position.getX() - 20, position.getY() - 40, 40, 40);
          this.name = name;
          this.position = position;
          this.category = category;
      }
  
      protected int[] getXs() {
          return xs;
      }
  
      protected int[] getYs() {
          return ys;
      }    
  
  protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              if (isShown) {
                  show(g);
              }
              if (isMarked) {
                  mark(g);
              }
          }
  
          protected void setShown(boolean b) {
              isShown = b;
              repaint();
          }
  
          protected boolean isMarked() {
              return isMarked;
          }
  
          protected void setMarked(boolean b) {
              isMarked = b;
              repaint();
          }
  
          protected void mark(Graphics g) {
              g.setColor(Color.MAGENTA);
              g.drawRect(0, 0, 39, 39);
          }
  
          protected void show(Graphics g) {
              if (category.equals("Bus")) {
                  g.setColor(Color.RED);
              } else if (category.equals("Underground")) {
                  g.setColor(Color.BLUE);
              } else if (category.equals("Train")) {
                  g.setColor(Color.GREEN);
              } else if (category.equals("None")) {
                  g.setColor(Color.BLACK);
              }
              g.fillPolygon(getXs(), getYs(), 3);
          }
  </code></pre>