I want to get the v=id from youtube\'s URL with java
Example Youtube URL formats:
http://www.youtube.com/watch?v=u8nQa1cJyX8&
6UW3xuJinEg (i mean the string after youtu.be/) is the ID most of the time. But for being more sure you can send HTTP GET request to that URL and it will respond you with a HTTP302 redirect response where you can find the actual redirection URL. you can parse that URL your previous code.

To send and recieve that request and response you can use libraries like jsoup. but because it's just a simple GET request you can simply use java sockets.
Connect to youtube.be on 80 port and write this in output stream:
GET /6UW3xuJinEg HTTP/1.1
# Don't forget the blank lines