Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public static void letterReversal(HashTableMap checkMap, HashTableMap dicMap, ArrayList<String> wordsAlreadyContained, String next, StringBuilder b){
  2.    
  3.         //loop for length of word being checked -1
  4.         for(int j=0; j < next.length()-1; j++){
  5.            
  6.             //split word up into characters and put into arraylist
  7.             ArrayList<String> list = new ArrayList<String>(Arrays.asList(next.split("")));
  8.            
  9.             //get character at j and store in temp
  10.             String temp = list.get(j);
  11.            
  12.             //set character at j to j+1
  13.             list.set(j, list.get(j+1));
  14.            
  15.             //set character at j+1 to j/temp
  16.             list.set(j+1, temp);
  17.            
  18.             //build up string from the characters in list
  19.             String s = BuildString.buildStr(list);
  20.            
  21.             //if string s can be found int he dictionary map and the word has not already been added then add it to the stringbuilder
  22.             //and arraylist of words already contained
  23.             if(dicMap.find(s) && !(wordsAlreadyContained.contains(s))){
  24.                
  25.                 //if this is the first time the word is being correct then add to stringbuilder
  26.                 if(!(wordsAlreadyContained.contains(next + " => "))){
  27.                     wordsAlreadyContained.add(next + " => ");
  28.                     b.append(next + " => ");
  29.                 }
  30.                
  31.                 b.append(s + ", ");
  32.                 wordsAlreadyContained.add(s);
  33.             }
  34.                
  35.            
  36.         }//close for loop
  37.                
  38.     }//close method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement