Java Reference
In-Depth Information
System.out.println("Could not determine when "
+ name + " was born.");
} else
{
System.out.println(name + " was born in " + resultYear);
}
In some cases, the program may not be able to determine the person's birth year. If this
occurs, the user is informed.
Searching Google
The first step is to submit the search to Google and get the results back.
Collection<GoogleSearchResultElement> result = new ArrayList<Googl
eSearchResultElement>();
int resultCount = 0;
int top = 0;
The search is submitted.
do
{
search.setQueryString("\"" + query + "\"");
search.setStartResult(top);
GoogleSearchResult r = null;
try
{
r = search.doSearch();
} catch (GoogleSearchFault e)
{
e.printStackTrace();
}
If search results were found, add them to the list and continue. Google returns
GoogleSearchResultElement objects for each of the URLs found.
if (r != null)
{
Object list[] = r.getResultElements();
resultCount = list.length;
for (int i = 0; i < resultCount; i++)
{
GoogleSearchResultElement element =
(GoogleSearchResultElement) list[i];
result.add(element);
}
}
Search WWH ::




Custom Search