I read on an assessment book that

a^3-b^3 = (a-b)[(a-b)^2-ab]

Can someone tell me how is a^3-b^3 converted into (a-b)[(a-b)^2-ab]?

Same for this:

a^3 + b^3 = (a+b)[(a+b)^2-3ab]
how do i get this??

It can be easily shown by long division that

a^3 + b^3 = (a+b)(a^2 - ab + b^2)
and
a^3 - b^3 = (a-b)(a^2 + ab + b^2)

If in your questions, you expand the second factor of the right side, you will end up with the above identities.