Is it useful to search code from the Internet?
Yes.
You won't be a good writer without reading a lot. You won't be a good programmer without reading lots of other people's code. As you gather experience, you'll get better at figuring which is good code. That's a big problem for novices in any field though.
Searching code does not mean finding it and pasting it into your project. It means reading to understand what techniques the programmer used, learning those techniques, and then applying it on your own.
Which one is better way in programming
Neither is better. You need to be fluent in both.
There's dearth of formal (as in "we paid competent people to write it") technical documentation for large systems built from disparate blocks, and many of the problems people run into are only "documented" because someone else ran into them and figured a solution, often at some pain. So searching solutions on Internet is a critically useful skill to have.
On the other hand, if all you do is search other people's solutions, you won't innovate much. So there's a balance. You read code to learn, not to copy.