For example, if U= {A, B, C} and V= {x, y} then the function f:U->V defined by A->x, B->y, C->y is onto but not one to one.
Conversely, the function g:V->U defined by x->A, y->B is one to one but not onto.
It can be shown that if two finite sets have the same cardinality, then a function is one to one if and only if it is onto.
That is not true for infinite sets. For example, the set, I, of all integers and the set, E, of all even integers have the same cardinality but f:E->I defined by f(x)= x is one to one but not onto while the function g:I->E, defined f(x)= x/2 if x is even, f(x)= (x- 1)/2 if x is odd, is onto but not one to one.