What would happen if I throw a grenade in space? Would it explode? Or will it just keep floating forever?
Yes, it would explode. Most hand grenades are nowadays triggered chemically, electrically or contain a fuze enclosed within the assembly, so they don't require atmospheric oxygen to ignite, are watertight and otherwise more reliably go off at a preset time since activation.
You would however create a large number of dangerous debris that would float forever, if exploded in higher orbits or deep space, or at least until they impact something, i.e. transfer their momentum onto another body. In lower orbits, the smaller the fragments, the lesser their kinetic potential and would eventually decay their orbit due to still some atmospheric pressure and thus atmospheric drag slowing them down. Depending on the materials these fragments are made of, and their surface area, they might evaporate on reentry, further disintegrate due to surface ablation into smaller fragments, or make it to ground at these fragments' terminal velocity more or less intact.
Do note though that if you're in Earth's orbit, you're orbiting it at many times the speed of firearm projectiles (roughly 7.7 km/s in LEO while firearm bullets usually achieve a bit over the speed of sound at sea level or even less, see e.g. this page for comparison), so while hand grenade fragments would travel away in all directions from the point of explosion, they would retain more-or-less same orbit you're in. They might boomerang (can it be used as a verb?) and hit you many orbits around the Earth later at same relative velocity they were at first moving away from you. Not recommended!
It depends on how long the grenade has been exposed to space. You might find the vacuum got to the mechanism if it's been out there long enough. Assuming the trigger doesn't fail due to vacuum welding it's going to go boom.