How to Merge Paragraphs java

Let’s say the document looks like this:

Hello, my name is XXXX.**
I am happy.

We want to merge the two paragraphs so that the output is this:

Hello, my name is XXXX.**I am happy.

(The ** are spaces)

Is there a built-in method for this?

@Mahesh39 To merge two paragraphs you should simply copy nodes from one paragraph to another and then remove an empty paragraph. For example see the following simple code:

Document doc = new Document("C:\\Temp\\in.docx");

// Get First and second paragraphs in the document
Paragraph p1 = doc.getFirstSection().getBody().getParagraphs().get(0);
Paragraph p2 = doc.getFirstSection().getBody().getParagraphs().get(1);

// Copy all nodes from one paragraph to another.
while (p2.hasChildNodes())
    p1.appendChild(p2.getFirstChild());

// Remove an empty paragraph.
p2.remove();

doc.save("C:\\Temp\\out.docx");