Greetings. I need your help again. I write a kind of program for encoding. There is a text that needs to be encoded. Let the array String[] text = {ace bdf} have a character set for encoding - final char[] KEY_WORDS = {'a','b','c','d','e','f'} . I run through the text and look for matches with the second array, and when I find it, I return the index of the match in the KEY_WORDS field to the newly created array. That is, I get a new array int[]total = {0,2,4,1,3,5} . There are no problems here. Now we need to decode it - take an array of total, and compare it with the KEY_WORDS array. But that's the problem - I need to compare the value with the total and the index in KEY_WORDS . thank
public static ArrayList arrayCodeNumber(char[] s, char[] ss) { ArrayList total = new ArrayList(); for (int i = 0; i < s.length; i++) { for (int j = 0; j < ss.length; j++) { if (s[i] == ss[j]) { total.add(j); } } } return total; } public static void main(String[] args) throws FileNotFoundException { String filename = "C:\\a.java"; char[] s = read(filename).toCharArray(); final char[] KEY_WORDS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '_', '-', ' '}; ArrayList a = arrayCodeNumber(s, KEY_WORDS); System.out.println(a); String[] output = new String[a.size()]; for (int i = 0; i != a.size(); i++) { output[i] = (String) a.get(i); System.out.println(output); } for (int i = 0; i < output.length; i++){ if (output[i] == ??? ) } } }
char c = KEY_WORLDS[total[0]);to get the entire row, loop through thetotalarray - pavlofff