I have trouble with comming up with a solution to my homework. How do i compare segments of my array and build a single string

This is my task. If there are some grammar mistakes it is because it is transelated from slovenian.

In the company, they have a large amount of data, which they store in files. Records consist of letters and/or numbers (without spaces). One day, one of the careless workers accidentally uploaded a virus to the company’s computers, which fragmented the contents of the files into smaller parts and mixed them together. The virus fragmented the contents of the file in the following way. Each line in the file is split into three or more strings separated only by spaces. Each line is fragmented within a line only, that is, all parts of a particular line are in the same line of the file and do not need to be searched elsewhere in the file. The only problem is that the individual parts of the line, into which the original line is divided, overlap in a certain number of characters (always at least one character). Your task is to write a program that will reassemble the fragmented lines of an individual file back into their original form. In doing so, it is necessary to find parts that match each other as closely as possible. Several remaining parts may match the end (or beginning) of a certain part, but only those two that match in the largest number of characters are folded together. But in order not to make the task too difficult, the first part of each individual line will always be in the first place in the line.

We have parts “110”, “01123”, “1011”. Both the beginning of the second part and the beginning of the first part coincide with the end of the third part. The second part matches in three characters, and the first in two, so the third part is finally combined with the second part in the string “101123”. The first part finally matches the beginning of the combined part in two characters and we get the final string “1101123”.
The file containing the data will be called “FileA.txt”. Your program should read the file and put the lines together accordingly. The final solution should be written in a new file called “FileB.txt”.

import java.util.*;
import java.io.*;

public class DomacaNaloga2
{
    public static void main (String[] args)
    {

        String imeDatoteke = "DatotekaA.txt";
        try 
        {
            ArrayList<String> vrstice = vrniArray(imeDatoteke);

        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        
        
        
        
    }
    

    
    public static void preberiDatoteko (String imeDatoteke) throws Exception
    {
        String ime = imeDatoteke;
        FileReader fr = new FileReader(ime);
        BufferedReader dat = new BufferedReader(fr);

        while(dat.ready())
        {
            System.out.println(dat.readLine());
        }
        dat.close();
    }
    
    
    public static ArrayList<String> vrniArray (String imeDatoteke) throws Exception
    {
        ArrayList<String> vrstice = new ArrayList<>();
        String ime = imeDatoteke;
        FileReader fr = new FileReader(ime);
        BufferedReader dat = new BufferedReader(fr);
        String vrstica;

        while(dat.ready())
        {
            vrstica = dat.readLine();
            vrstice.add(vrstica.trim());
        }
        dat.close();
        return vrstice;
    }
    
    public static ArrayList<String> zdruziVrstice(ArrayList<string> vrstice)
    {
        ArraysList<String> zdruzeniNizi = new ArrayList<>();
        for(int i = 0; i<vrstice.size(); i++)
        {
            String trenutna_vrstica = vrstice.get(i)
        }
    }
    
    
    
}
    

This is my code for now, i cannot seem to develop an alghorithm to solve this issue. All help would be usefull. I suppose i need to create a for loop of somekind to compare the objects in the array but to be honest i do not fully understand the task either and the proffesor is on vacation and the date to finish is in midnight so please help me guys.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật