we have lots of strings eg String s1="I love India",s2="I love you" , I have to search these strings based on words.if I search for "I" String s1 and s2 must be displayed.If if search for "India" only s1 be displayed. It works similar to google search

can anyone give me any suggestions

We can achieve these using java string matching functions.

public class Search {

// Original Strings
public static void main(String[] args) {
	Search search = new Search();
	
	//Searching for I string
	List<String> results1 = search.searchString("I");
	
	for(String matchedStrings : results1)
		System.out.println("String " +"\"" + matchedStrings +"\"" +" Contains I " );
	
	//Searching for India string
	List<String> results2 = search.searchString("India");
	
	for(String matchedStrings : results2) 
		System.out.println("String " +"\"\"" + matchedStrings +"\"\"" +" Contains India" );
}

// This method returns all the matched strings 

public List<String> searchString(String strSearchTerm) {
	
	List<String> results = new ArrayList<String>();
	
	List<String> originalStrings = new ArrayList<String>();
	
	originalStrings.add("I love India");
	
	originalStrings.add("I love you");
	
	for(String originalString: originalStrings) {
		
		int index = originalString.toLowerCase().indexOf(strSearchTerm.toLowerCase());
		
		if(index != -1) {
			results.add(originalString);
		}
		
	}
	return results;
}

}

//