Question: ```
MAP_PERSONAL_DATA_WITH_TAG = {"Flat/Unit No." => "FLD_ADD_1Line1",
                          "Building No./Name" => "FLD_ADD_2Line2",
                          "Street" => "FLD_ADD_3Line3",
                          "Postcode" => "FLD_ADD_4Postcode",
                          "City/Town" => "FLD_ADD_5City",
                          "Region" => "FLD_ADD_6State",
                          "Suburb" => "FLD_ADD_Town"
}

data_hash = {"Street" => "s", "Suburb" => "sb", "abc" => "hdkhd"}

data_hash.each do |key, value|
  case key
  when  <if key equal to the key of MAP_PERSONAL_DATA_WITH_TAG i.e    MAP_PERSONAL_DATA_WITH_TAG.has_key?(key)>
    puts 'something'
  when "Mobile"
    puts "something mobile"
  else
    puts 'something else'
  end
end

```

Rather than writing like 

when "Flat/Unit No.","Building No./Name","Street","Postcode","City/Town","Region","Suburb"

Is there any better way to write this?

Answer: 
Instead of checking for all words that have the letter "a" check for all words that have an 'a' in the second position. You can use `string.charAt(1) == 'a'` to accomplish this.

You could write a method that checks an array for letters and returns an `ArrayList` with all of the words like this.

```
public static List<String> getWords(String[] words, char c, int position) {
    List<String> result = new ArrayList<String>;
    for (String s : words) {
        if (position > s.length - 1)
            continue;
        if (s.charAt(position) == c)
            result.add(s);
    }
    return result;
}

```
There are several options. I have tried to showcase several of those. You will notice that I have used some Java 8 specific concepts, specifically Stream's and Lambda's. Streams will allow you to handle bigger data sets because of the possibility to parallelize your word matching.

```
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Play {
  static class Method {
    private Predicate<String> method; 
    private String name;
    Method(String name,Predicate<String> method) {
      this.name = name;
      this.method = method;
    }
  }
  public static void main(String[] args) {
    String [] words = {"axe","bow","car","eye","fat","pig","sun","bla"};
    Method [] methods = new Method [] {
      new Method("Method 1",(s)->s.matches(".a.")),
      new Method("Method 2",(s)->s.charAt(1)=='a'),
      new Method("Method 3",(s)->s.indexOf('a')==1),
      new Method("Method 4",(s)->s.matches(".{1}a.*")),
      new Method("Method 5",(s)->s.substring(1,2).equals("a")),
      new Method("Method 6",(s)->s.substring(1).startsWith("a")),
      new Method("Method 7",(s)->s.startsWith("a", 1)),
    };
    Stream.of(methods).forEach((method)->{
      System.out.append(method.name).println(":");
      Stream.of(words).filter(method.method).forEach(System.out::println);
    });
  }
}

```

If you have picked one of the option, you can easily put it in a method as follows:

```
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Play {
  public static List<String> getWords(String[] words, char c, int position) {
    return Stream.of(words)
            .filter((s)->position < s.length())
            .filter((s)->s.charAt(position)==c)
            .collect(Collectors.toList());
  }
  public static void main(String[] args) {
    List<String> matches = getWords(
      new String [] {"axe","bow","car","eye","fat","pig","sun","bla","a"},'a',1
    );
    matches.stream().forEach(System.out::println);
  }
}

```