Q:

Declaring a method within parameter input of an other method? 

I was looking for a way to get all the files ending with .txt in the current directory.  I found the answer of how to do this here https://stackoverflow.com/a/5751357/3972558 and it works.  Now I am reviewing my own code and I still do not quite understand how this works, and I am trying to learn from that. 
    File workingDirectory = new File(System.getProperty("user.dir"));
    File[] files = workingDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".txt");
        }
    });

How is it possible that you declare a method within where you would usually find a parameter input?  I probably ask my question in the wrong way because I do not understand why this syntax is correct. 
In specific, how is this a correct input of listFiles(): 
new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".txt");
            }
        }

Update: I now see that indeed you're implementing the accept method for the FileNameFilter interface.  How is it possible though that you implement it after the keyword new.  
http://docs.oracle.com/javase/7/docs/api/java/io/File.html
http://docs.oracle.com/javase/7/docs/api/java/io/FileFilter.html

A:

Ok FilenameFilter is a abstract class, with the abstract method accept().  You have to implement this and all other stuff (e.g. comparing each filename), will done by FilenameFilter.  You have to implement it after new because for creating a new Filter Java has to know in wich way you want FilenameFilter to work. 
It's a basic idea of java to make some method abstract and you have to implement it on the way to say what you want to do in your special case.  I hope it makes it a little bit more clear!