Regular Expressions Pattern Java -


i'm still not sure how deal regular expressions. have following method takes in pattern , return number of pictures taken in year.

however, method takes in perimeter year. intending string pattern = \d + "/" + year; means month wildcard year must matched.

however, code doesn't seem work. can guide me on regular expressions? expected string passed in should "9/2014"

    // method returns number of pictures taken in     // specified year in specified album. example, if year 2000 ,     // there 2 pictures in specified album taken in 2000     // (regardless of month , day), method should return 2.     // ***********************************************************************      public static int countpicturestakenin(album album, int year) {         // modify code below return correct value.         string pattern = \d + "/" + year;          int count = album.getnumpicturestakenin(pattern);         return count; } 

if understand question correctly, need:

public class { public static void main(string[] args) {      int count = countpicturestakenin(new album(), 2016);     system.out.println(count); }  public static int countpicturestakenin(album album, int year) {     // modify code below return correct value.     string pattern = "[01]?[0-9]/" + year;      int count = album.getnumpicturestakenin(pattern);     return count; }  static class album {     private list<string> files;      album() {         files = new arraylist<>();         files.add("01/2016");         files.add("01/2017");         files.add("11/2016");         files.add("1/2016");         files.add("25/2016");     }      public int getnumpicturestakenin(string pattern) {         return (int) files.stream().filter(n -> n.matches(pattern)).count();     } } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -