Hi all,
I am having a file contains key and value pairs separated by space.
I want to read that text file and store into a data structure in java so that, If i want to search a key in file then it should have to iterate only upto the length of search string (key) entered by end user, not to iterate through the whole file for searching the matching key.
e. g. If the keys in file are like
java, java program, java programming
and if the search string is like "Programming"
then the search should like :
if array[0][p] = "p" -> false
if array[1][r] = "pr" -> false
if array[2][o] = "pro" -> false
if array[3][g] = "prog" -> false
if array[4][r] = "progr" -> false
if array[5][a] = "progra" -> false
if array[6][m] = "program" -> true //match found
if array[7][m] = "programm" -> false
if array[8][i] = "programmi" -> false
if array[9][n] = "programmin" -> false
if array[10][g] = "programming" -> true //match found
so the longest match is 10
Then the program should have to return the value related to the key " java programming".
Please suggest how can we achieve the same feature using java.