You use a cast to tell the compiler: "I have an object of type X here, but I know better than you what it really is, so I want you to treat it as type Y and not complain".
That's exactly what's happening in your code. You know that the first element in the list is a String, but List.get(...) returns an Object. You use a cast to tell the compiler that it should assume that the object is a String. Likewise with the Dog and the Integer object.
Note that
Java will still check at runtime if the object you're casting really is of the type you're casting it to. If it isn't, you'll get a ClassCastException.