How to change apple Id on iPhone 3gs?

I've brought a second hand iPhone and I need to change the apple Id without restoring it as I know sometimes that can cause problems, anyone know how to do this it would be a great help thanks.

Depending on your iOS version, you need to enter "Settings", then find "iTunes and App Stores".
Inside, if there's currently a logged in Apple ID, you can log out of it by pressing the email address of the Apple ID in the middle of the screen, then you should get the option to "logout".

Once you've logged out, you can log in into your own Apple ID, or simply create a new one.