Code below. It divides the line into smaller smaller pods (chunks of a fixed size, for example 10), a two-dimensional array is obtained, where the main array is the number of chunks and the subarray is the number of characters in the chunk (10). You need to override the subSequence method, which gets the range of the string that you want to pull out of the main two-dimensional array. The problem is that it’s impossible to copy certain values ​​from the main array into the subarray, which I create in this method (i.e., if the range started in one chunk and ends in another, you need to pull a quantitative value in this chunk). I set the offset that is between the chunks, only three chunks of 25, 84 elements, I need elements from 26 to 56. That is, the beginning is in the first chunk, the end is in the second -> the required range is difficult to set using integers.

package edu.technopolis; import java.util.Arrays; import java.util.stream.IntStream; public class CustomString implements CharSequence { private char [][] chars; private String inputS; private final int DEFAULT_CHUNK_LENGTH = 10; private int offset; private int tmpLength; private int count; private CustomString( char[][] chars) { this.chars = chars; } @Override public CharSequence subSequence(int start, int end) { if (start < 0 || end < 0 || end > inputS.length() || start > end) { throw new IndexOutOfBoundsException("out of border"); } char [][] chars; this.offset = start; // задаем смещение this.count = end - start; // задаем количество int chunk_start = start / DEFAULT_CHUNK_LENGTH; int chunk_end = end / DEFAULT_CHUNK_LENGTH + 1; if(count < DEFAULT_CHUNK_LENGTH){ chars = new char[(count / DEFAULT_CHUNK_LENGTH) + 1][count]; } else { chars = new char[(count / DEFAULT_CHUNK_LENGTH)][count]; // выделяем память под кусок и под количество сабстринтов for (int i = 0; i < (count / DEFAULT_CHUNK_LENGTH); i++) { // идем циклом от 0 до целого количества, необходимого нам чтобы заполнить первый массив for (int j = 0, k = offset; j < count; j++, k++) { // идем от нуля до количества элементов, ставим k в offset chars[i][j] = this.chars[][k]; // что писать тут? } } } return new CustomString(chars); } public CustomString(String inputS) { this.offset = 0; this.count = 0; this.inputS = inputS; this.tmpLength = this.inputS.length(); if(this.inputS.length() == 0) { return; } if(inputS.length() % DEFAULT_CHUNK_LENGTH == 0) { this.chars = new char[this.inputS.length() / DEFAULT_CHUNK_LENGTH][this.inputS.length()]; for(int i = 0, j = 0; i < this.inputS.length()/DEFAULT_CHUNK_LENGTH; i++){ for(int indexInputS = 0; indexInputS < DEFAULT_CHUNK_LENGTH;indexInputS++,j++){ this.chars[i][j] = this.inputS.charAt(indexInputS); } } } else if(inputS.length() % DEFAULT_CHUNK_LENGTH != 0) { this.chars = new char[(this.inputS.length() / DEFAULT_CHUNK_LENGTH) + 1][]; //выделил ровно столько, сколько нужно for(int i = 0; i < this.inputS.length() / DEFAULT_CHUNK_LENGTH; i++){ // this.chars[i] = new char[DEFAULT_CHUNK_LENGTH]; // выделил чанку память } this.chars[this.inputS.length()/DEFAULT_CHUNK_LENGTH] = new char[this.inputS.length() % DEFAULT_CHUNK_LENGTH]; //выделил ровно столько, сколько нужно сабстрингу for(int i = 0; i < this.inputS.length(); i++){ this.chars[i/DEFAULT_CHUNK_LENGTH][i%DEFAULT_CHUNK_LENGTH] = this.inputS.charAt(i); } } } @Override public int length() { return this.inputS.length(); } @Override public char charAt(int index) { if ((index < 0) || (index >= inputS.length())) { throw new StringIndexOutOfBoundsException(index); } return this.chars[index/DEFAULT_CHUNK_LENGTH][index%DEFAULT_CHUNK_LENGTH]; } @Override public String toString(){ StringBuilder tmp = new StringBuilder(); for(int i = 0; i < tmpLength; i++ ){ tmp.append(this.chars[i/DEFAULT_CHUNK_LENGTH][i%DEFAULT_CHUNK_LENGTH]); } return tmp.toString(); } } 
  • upd - I, for example, set the offset that is between the chunks, Ie this is not an integer, say, only three chunks of 25, 84 elements, I need elements 26 through 56. That is, the beginning in the first chunk, the end in the second -> the desired range is difficult to set, using integers. - Kilinochi
  • do not use as many introductory words. This is not an essay, but a specific question. - michael_best

0