Distinct objects into distinct boxes: two different statements? I am having a little doubt in these two statements for the following same problem.: No. of ways of distributing $n$ different objects into k different bins. I was going through A Walk through Combinatorics and according to it:

If we have to put n different balls into k different boxes then the number of ways to do this is $k!S(n,k)$, where $S(n,k)$ is Stirling number of second kind.

The explanation goes like this:-

first we can partition $[n]$ into $k$ non-distinguishable parts in $S(n, k)$ ways, then we can label the $k$ parts with labels $1,2, \cdots, k$ in $k!$ different ways.

And then this statement

Suppose there are $n$ distinct objects that are to be distributed among $r$ distinct bins. This can be done in precisely $r^n$ ways.

Please pardon me if the question is stupid, but I am in confusion.
 A: The Stirling number of the second kind $S(n, k)$ counts the number of ways of ways of distributing $n$ distinct objects to $k$ indistinguishable boxes when no box is left empty.  Therefore, the formula $k!S(n, k)$ counts the number of ways of distributing $n$ distinct objects to $k$ distinct boxes when no box is left empty.
On the other hand, $r^n$ counts the number of ways of placing $n$ distinct objects in $r$ distinct bins without restriction, meaning that some of the boxes may be left empty.
A: "Different to different" statement is equivalent to the number of functions $f:A\to B$ with $|A|=n$ and $|B|=k$. Then it depends if you allow repetitions (of bins in this case) or not and if you allow some element in $B$ to be assigned to no elements in $A$.
In this specific case you look for the total number of functions among those sets, since I guess you are allowed to repeat bins and to left some of them empty: this number is $k^n$.
Why?
Because take every element into the domain, there are $k$ possibilities for it to go to an element of the image. Same things with the others. Of course you need to multiply them together and thus you get the answer.
