Follow these steps to implement the example:
- Create a class named DocumentMock. It will generate a string matrix that will simulate a document:
public class DocumentMock {
- Create an array of strings with some words. This array will be used in the generation of the strings matrix:
private String words[]={"the","hello","goodbye","packt", "java","thread","pool","random", "class","main"};
- Implement the generateDocument() method. It receives as parameters the number of lines, the number of words per line, and the word the example is going to look for. It returns a matrix of strings:
public String[][] generateDocument(int numLines, int numWords, String word){
- First, create the necessary objects to generate the document-the ...