Q:

What does xargs do exactly in this case? 

I recently came across the following two examples
Example 1: List only directories
ls -l | grep "^d"

Example 2: Search inside files
   ls | xargs grep -i "Find Some String"

Now i have read from here that

If you just use a pipe, it receives data on STDIN (the standard input
  stream) as a raw pile of data that it can sort through one line at a
  time. 

So now I am a little confused as to why grep requires xargs in the second one and not in the first one.  From what I understand so far is that xargs is used for converting stdin into arguments. ( Since some programs require arguments instead of stdin).  Does this mean grep can take both stdin and arguments ?  I would appreciate it if some one could explain why is xargs used in the second example why cant it work without xargs?  What purpose is it serving ? 

A:

In example 2 , you are searching for a certain text in the file contents, so you need xargs to pass the file names to grep. 
In example 1, you are searching the output of ls, not the file contents.   
actually, you can search file content without using xargs, which is better:  
grep -i 'some text' *

