The problem is that I can output it, but when I display it, I get this picture

In the textfield, the first key

What should I do to show me the array symbols, and not these?

private HashMap<Integer, char[]> map = new HashMap<>(); char[] arrayOfChars =null; @FXML public void onEncrypt(){ toArrays(text.getText()); for (int i = 1; i<6 ;i++){ if(i==1){ for(int j=0; j<5;j++){ char[] podArray =new char[5]; podArray[j] = arrayOfChars[j]; map.put(i,podArray); } } if(i==2){ for(int j=5; j<10;j++){ char[] podArray =new char[5]; podArray[j-5] = arrayOfChars[j]; map.put(i,podArray); } } if(i==3){ for(int j=10; j<14;j++){ char[] podArray =new char[5]; podArray[j-10] = arrayOfChars[j]; map.put(i,podArray); } } if(i==4){ for(int j=15; j<20;j++){ char[] podArray =new char[5]; podArray[j-15] = arrayOfChars[j]; map.put(i,podArray); } } if(i==5){ for(int j=20; j<25;j++){ char[] podArray =new char[5]; podArray[j-20] = arrayOfChars[j]; map.put(i,podArray); } } } firstKey.setText(map.get(1).toString()); } private void toArrays(String text) { arrayOfChars = text.toCharArray(); } } 

    1 answer 1

    To output an array:

     StringBuilder sb = new StringBuilder(); char [] array = map.get(1); for (char aChar : array) { sb.append(aChar); sb.append(" "); } firstKey.setText(sb.toString()); 

    Along the way, I’ll say that it seems to me that you fill the array incorrectly. Its initialization and saving to the map should occur outside the loop. For example:

     if(i==1){ char[] podArray =new char[5]; for(int j=0; j<5;j++){ podArray[j] = arrayOfChars[j]; } map.put(i,podArray); }