title: How to match Tree map value which starts with or equals search string
body: <p>I have a tree map</p>
  
  <pre><code>    TreeMap&lt;String,HashSet&lt;String&gt;&gt; kewordVideo = new TreeMap&lt;String,HashSet&lt;String&gt;&gt;();
  </code></pre>
  
  <p>and </p>
  
  <pre><code> String searchString;
  </code></pre>
  
  <p>I want to print all the values of Tree map which Starts with or equals searchString</p>
  
  <p>For example Tree map has following key value pair</p>
  
  <pre><code>v1 abc
  v2 abd
  v3 bcd
  v4 bad
  </code></pre>
  
  <p>and searchString is a</p>
  
  <p>So output should be</p>
  
  <pre><code>v1 v2 
  </code></pre>
  
  <p>as both of them start with a v4 should not be part of output as it does not starts with a or equals to a
  Here is complete code . No output is coming after i enter search key</p>
  
  <pre><code> package cultureMachine;
  
   import java.io.BufferedReader;
   import java.io.IOException;
   import java.io.InputStreamReader;
   import java.util.HashSet;
   import java.util.Map;
   import java.util.Map.Entry;
   import java.util.Set;
   import java.util.TreeMap;
  
   public class CultureMachineAssignment {
  
   TreeMap&lt;String,HashSet&lt;String&gt;&gt; kewordVideo = new      TreeMap&lt;String,HashSet&lt;String&gt;&gt;();
  TreeMap&lt;String,HashSet&lt;String&gt;&gt; videoKeyword =  new TreeMap&lt;String,HashSet&lt;String&gt;&gt;();
  TreeMap&lt;String,Integer&gt; keywordLength = new TreeMap&lt;String,Integer&gt;();
  
     public static void main(String args[]) throws IOException {
  
       CultureMachineAssignment obj1 = new CultureMachineAssignment();
  
  
       Integer previousVal=0;
       InputStreamReader ip = new InputStreamReader(System.in);
       BufferedReader br = new BufferedReader(ip);
  
       for(int i=0;i&lt;5;i++){
          System.out.println("Enter Video name");
          String video =br.readLine();
  
  
          if(!obj1.videoKeyword.containsKey(video)){
              obj1.videoKeyword.put(video,new HashSet&lt;String&gt;());
          }
  
          System.out.println("Enter keywords for video");
          String keyword =br.readLine();
  
          if(!obj1.keywordLength.containsKey(video))
              obj1.keywordLength.put(video, 0);
  
          if((obj1.keywordLength.get(video)+keyword.length())&lt;5){
              obj1.videoKeyword.get(video).add(keyword);
              previousVal=obj1.keywordLength.get(video);
              obj1.keywordLength.put(video, previousVal+keyword.length());
          }
          else{
              System.out.println("Maximum length exceeded for video "+ video);
              break;
          }
          if(!obj1.kewordVideo.containsKey(keyword)){
              obj1.kewordVideo.put(keyword,new HashSet&lt;String&gt;());
          }
          obj1.kewordVideo.get(keyword).add(video);
  
  
      }
      for(Map.Entry m:obj1.videoKeyword.entrySet()){  
          System.out.println(m.getKey()+" "+m.getValue());  
      }
      System.out.println("Enter keyword to search video");
      String searchKey = br.readLine();
      for(Entry&lt;String,HashSet&lt;String&gt;&gt; entry : obj1.kewordVideo.entrySet()){    
                    if(entry.getValue().contains(searchKey))
                       System.out.println(entry.getKey());
  
                  }
          }   
   }
  </code></pre>