title: How to retrieve values from ArrayList<String> if the latter is a Key in Map?
body: <p>I am new to Java. Now I'm trying to work with a structure like</p>
  
  <pre><code> Map&lt;List&lt;String&gt;,String&gt;    
  </code></pre>
  
  <p>..and there are difficulties with retrieving Strings from the List. </p>
  
  <p>Details: 
  I am making a simple program which takes phone numbers and checks to which country specific number belongs. It checks them via matching with regular expressions (underlying digit amount and international prefix: because prefixes (and thus - regular expressions) may be more then one - List is chosen). </p>
  
  <p>So, the structure of regex is:</p>
  
  <pre><code>"^(%s)\\d{%d}", prefix, digitAmount    
  </code></pre>
  
  <p>There are some basic data for some numbers (Finnish, English), but user can also add new ones (example: Gonduras - prefix: 849, number of digits: 8, Gonduras (same) - prefix 49, number of digits: 7 etc.) 
  So when you will enter a number like 893143045839 - it should find whether it matches regular expression. And if it is, return the country (a value). That's why the Map is chosen. </p>
  
  <p>The code here is:</p>
  
  <pre><code>static Map &lt;List&lt;String&gt;, String&gt; data = new HashMap&lt;List&lt;String&gt;, String&gt;();
  static List&lt;String&gt; newdata = new ArrayList&lt;String&gt;();
  
  void addBasicData ()  // here I add some predefined parameters
  {
  List&lt;String&gt; finnNumbers = new ArrayList&lt;String&gt;();
  finnNumbers.add("^(3589)\\d{6}");
  finnNumbers.add("^(003589)\\d{6}");
  finnNumbers.add("^(09)\\d{6}");
  data.put(finnNumbers, "Finland");
  }
  
  
  void addNewData (String pattern, List&lt;String&gt; newdata)   //here I add new data from user
  {
  pattern();
  data.put(newdata, pattern);
  }    
  </code></pre>
  
  <p>The problem occurs further. When I want to check some number, I have to make a pattern - which should take the regex from the data. Well, it appears that I can't. 
  Here is the method..</p>
  
  <pre><code>void numberCheck (String inputNumber)
  {
  
  // maybe I'll use Set values = data.keySet(); ? ...nah, doesn't work either :(
  
  
  for (int i = 0; i&lt;= data.size(); i++)
  {
      Object c = data.get(i);
      List&lt;String&gt; check = (List&lt;String&gt;)c;
      for (int j = 0; j &lt;check.size(); j++)   
      {
  
          Pattern pat = Pattern.compile(check.get(j));
          Matcher matcher = pat.matcher(inputNumber);
          if (matcher.find())
          {
              // some useful code
          }
  
      }
  
  
  }
  </code></pre>
  
  <p>.., which do not work and gives NullPointerException. When I want to take a key and then try each regex as a pattern, it instead gives me an Object, not an ArrayList. That's why I am asking.
  I tried to use it reverse-like ( Map> ), but then I need to iterate values, and there is the same problem. </p>
  
  <p>This is the point</p>
  
  <pre><code>    Object c = data.get(i);
      List&lt;String&gt; check = (List&lt;String&gt;)c;
  </code></pre>
  
  <p>, where everything collapses. 
  Perhaps, I'm doing it entirely wrong and should use another classes in my case. </p>
  
  <p>I would be glad, if anyone can give an advice. Thank you!</p>