How to set page title in Magento 2?

In Magento 2, We can set page title using Controller as well as Using XML. I have given example for set page title using Controller and XML Way.

Using Controller,

public function execute() {
    $this->_view->loadLayout();
    $title = __('Page Title');
    $this->_view->getPage()->getConfig()->getTitle()->prepend($title);
    $this->_view->renderLayout();
}

Using Controller, We can set title by just call line¬† $this->_view->getPage()->getConfig()->getTitle()->prepend(‘title name’)

Using XML,

<head>
    <title>title name of page</title>
</head>

Using XML you can set your page title by <title> tag in <head> section.