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');

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

Using XML,

    <title>title name of page</title>

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