Language detection is notoriously difficult, but searching for "language detection java" finds several promising leads. Not sure how well those work if the text in question includes words in multiple languages, though.
You're taking a question originally posted on StackOverflow and repost it here? What's the point of that? Have you worked through all the answers given over there, and found them all to be lacking?