How to set page title in Magento 2?

In Magento 2, We can set page titles using Controller as well as Using XML.

I have given examples for setting page titles using Controller and XML Way.

Using Controller,

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

Using Controller, You can set the title by just calling 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.