Im brand new to Java and I came across the following problem.
Im looking at a list of movies from a txt file, one of the fields is a string representation of which genre is classified as a movie, as well as a numerical representation of 1-5, meaning the movie has received one or more awards.
EX. one film may have the following meaning in this field β12bStβ, this would mean that the film is b = biographical, S = sports, 2 = received an Academy Award. atm i do this:
String[] genreStringToArray(String genre) { char[] genreCharArray = genre.toCharArray(); this.genreArr = new String[genreCharArray.length]; for (int i = 0; i < genreCharArray.length; i++) { switch (genreCharArray[i]) { case 'a': genreArr[i] = "Action"; break; case 'A': genreArr[i] = "Animation"; break; case 'b': genreArr[i] = "biographical"; break; case 'c': genreArr[i] = "comedy"; break; case 'C': genreArr[i] = "children"; break; case 'd': genreArr[i] = "drama"; break; case 'D': genreArr[i] = "documentary"; break; case 'e': genreArr[i] = "epic"; break; ..... etc case 2:genreArr[i] = "Academy award"; break; case 3:genreArr[i] = "Palme d`or"; break; case 4:genreArr[i] = "Sight & sound"; break; case 5:genreArr[i] = "AFI top 100"; break; } } return genreArr; }
My question is: which implementation will be more efficient than this?
Jeger source share