{"id":77178,"date":"2020-03-13T10:47:26","date_gmt":"2020-03-13T05:17:26","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77178"},"modified":"2020-03-13T10:47:26","modified_gmt":"2020-03-13T05:17:26","slug":"java-comparator-interface","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/","title":{"rendered":"Java Comparator Interface &#8211; Enhance your Knowledge with its Rules &amp; Methods"},"content":{"rendered":"<p>There are many situations when we often need to compare two values in our Java programs. Comparing primitive values like int, char, float, boolean, etc., is very easy and we can compare them using the comparison operators like <strong>&lt;, &gt;, ==, etc.<\/strong><\/p>\n<p>But what if we want to compare objects? For example, How would you compare two Employees? For this purpose, Java provides two interfaces, which are <strong>Comparable<\/strong> and <strong>Comparator Interface in Java.<\/strong><\/p>\n<p>In our previous tutorial, we discussed the<a href=\"https:\/\/techvidvan.com\/tutorials\/java-interface\/\"> <em><strong>Interface in Java<\/strong><\/em>.<\/a> Continuing the chain today we are going to learn about the comparator interface in Java programming. Comparator Interface is one of the most useful topics in Java.<\/p>\n<p>The Comparator interface is an example of the Java library. We will also cover how to sort a collection with Java comparator with the example along with the working of Collections.Sort().<\/p>\n<p>So, let\u2019s start learning about Comparator Interface in Java.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/rules-for-java-comparator-interface.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77486\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/03\/rules-for-java-comparator-interface.jpg\" alt=\"Rules for Java Comparator Interface\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<h3>Java Comparator Interface<\/h3>\n<p>Comparator Interface in Java is used to arrange or sort the objects of user-defined classes. For example, for a list of students&#8217; objects, the natural order may be the order of employee unique id.<\/p>\n<p>But in real-life applications, we may want to sort the list of students by their first name, date of birth, year of admission, or simply any other such criteria. In such conditions, there is a need for the Comparator interface.<\/p>\n<p>The Comparator interface of Java is present in <strong>java.util<\/strong> package. This interface contains 2 methods <strong>compare(Object obj1, Object obj2)<\/strong> and <strong>equals(Object element).<\/strong><\/p>\n<p>By default, we can not compare the objects of a user-defined class. To make an object of a user-defined class comparable, the class must implement the <strong>Comparable<\/strong> interface.<\/p>\n<p><em><strong>Get familiar with the concept of <a href=\"https:\/\/techvidvan.com\/tutorials\/java-class\/\">Java Classes and Objects<\/a> in detail with Techvidvan.<\/strong><\/em><\/p>\n<p><strong>We can use the Comparator interface in the following situations:<\/strong><\/p>\n<ul>\n<li>Use to sort or arrange the list or array of objects, other than the natural order.<\/li>\n<li>To arrange the array or list of objects where we can not modify the source code of an object to implement a Comparable interface.<\/li>\n<li>Use to sort the same array or list of objects in different fields.<\/li>\n<li>To use the group by sorting on a list or array of objects in different fields.<\/li>\n<\/ul>\n<p>Now, let\u2019s understand the various methods of Java Comparator.<\/p>\n<h3>Methods of Java Comparator Interface<\/h3>\n<p>There are two methods of the Comparator Interface in Java, namely:<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td><b>Methods<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">compare(Object obj1,Object obj 2)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compares the first object with another.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">equals(Object obj)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Compares the current object with the specified object.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Comparator.compare() Method<\/h4>\n<p>The compare method is used to compare two objects.<\/p>\n<p><strong>Its syntax is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public int compare(Object obj1, Object obj2)<\/pre>\n<p>This method compares its two arguments in order. It returns &#8211;<\/p>\n<ul>\n<li><strong>a negative integer<\/strong>\u00a0if the first argument is smaller than the second argument.<\/li>\n<li><strong>zero,<\/strong> if the first argument is equal to the second argument.<\/li>\n<li><strong>a positive integer,<\/strong> if the first argument is larger than the second argument.<\/li>\n<\/ul>\n<p><strong>For Example:<\/strong><\/p>\n<p>Suppose we have a Java array or an array list of our own class that contains fields like <em>unique id, name, age, gender, etc.,<\/em> and we have to sort the list in the order of name or age. For this we can follow two approaches:<\/p>\n<p><strong>Approach 1:<\/strong><\/p>\n<p>One obvious approach is to compose our own method <strong>sort()<\/strong> by writing standard calculations in it. This will require going through the entire code for various basis like <em>id, name, etc.<\/em><\/p>\n<p><strong>Approach 2:<\/strong><\/p>\n<p>Using this approach we can utilize the <strong>comparator interface <\/strong>&#8211; Java Comparator interface sorts the objects of a user-defined class. This interface in Java is available in java.util bundle package and contains 2 functions <strong>compare (Object obj1, Object obj2) and equals (Object obj).<\/strong><\/p>\n<p><em><strong>Get to know more about <a href=\"https:\/\/techvidvan.com\/tutorials\/java-array\/\">Java Array<\/a> in detail with Techvidvan.<\/strong><\/em><\/p>\n<p><strong>Code to understand Collections.sort()<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.comparators;\nimport java.util.*;\n\/\/ A class to represent an employee\nclass Employee\n{\n  int id, salary;\n  String name;\n  \/\/ Constructor\n  public Employee(int id,int salary , String name)\n  {\n    this.id = id;\n    this.salary= salary;\n    this.name = name;\n  }\n  \/\/ Used to print student details in main()\n  public String toString()\n  {\n    return this.id + \" \" + this.name+\n        \" \" + this.salary;\n  }\n}\n\nclass SortById implements Comparator&lt;Employee&gt;\n{\n  \/\/ Used for sorting in ascending order of id\n  public int compare(Employee a, Employee b)\n  {\n    return a.id - b.id;\n  }\n}\n\nclass SortByName implements Comparator&lt;Employee&gt;\n{\n  \/\/ Used for sorting in ascending order of name\n  public int compare(Employee a, Employee b)\n  {\n    return a.name.compareTo(b.name);\n  }\n}\n\nclass SortBySalary implements Comparator&lt;Employee&gt;\n{\n  \/\/Used for sorting in ascending order of roll salary\n  public int compare(Employee a, Employee b)\n  {\n    return a.salary - b.salary;\n  }\n}\n\n\/\/ Driver class\npublic class ComparatorInterfaceDemo\n{\n  public static void main (String[] args)\n  {\n    ArrayList&lt;Employee&gt; list = new ArrayList&lt;Employee&gt;();\n    list.add(new Employee(111, 150000,\"Rajeev\"));\n    list.add(new Employee(131, 100000,\"Amit\"));\n    list.add(new Employee(121,250000, \"Minie\"));\n\n    System.out.println(\"Unsorted List\");\n    for (int i=0; i&lt;list.size(); i++)\n      System.out.println(list.get(i));\n\n    Collections.sort(list, new SortById());\n    System.out.println(\"\\nSorted by ID\");\n    for (int i=0; i&lt;list.size(); i++)\n      System.out.println(list.get(i));\n\n    Collections.sort(list, new SortByName());\n    System.out.println(\"\\nSorted by Name\");\n    for (int i=0; i&lt;list.size(); i++)\n      System.out.println(list.get(i));\n\n    Collections.sort(list, new SortBySalary());\n    System.out.println(\"\\nSorted by Salary\");\n    for (int i=0; i&lt;list.size(); i++)\n      System.out.println(list.get(i));\n\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Unsorted List<br \/>\n111 Rajeev 150000<br \/>\n131 Amit 100000<br \/>\n121 Minie 250000<br \/>\nSorted by ID<br \/>\n111 Rajeev 150000<br \/>\n121 Minie 250000<br \/>\n131 Amit 100000<br \/>\nSorted by Name<br \/>\n131 Amit 100000<br \/>\n121 Minie 250000<br \/>\n111 Rajeev 150000<br \/>\nSorted by Salary<br \/>\n131 Amit 100000<br \/>\n111 Rajeev 150000<br \/>\n121 Minie 250000<\/div>\n<h3>Rules for Java Comparator Interface<\/h3>\n<p>There are certain rules for using Java Comparator Interface, they are as follows &#8211;<\/p>\n<ul>\n<li>You need to implement a Comparator interface if you want to sort the elements of a collection.<\/li>\n<li>You will need to mention the type of the parameter as Object when you override the compare() method. Because, if you do not specify any type of object in your Comparator interface, then, by default, it assumes that you are going to sort the objects of type Object.<\/li>\n<li>If you want to sort the elements of a user-defined type, then you need to specify the user-defined type generically while implementing the Comparator <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/concepts\/interface.html\">interface<\/a>. When you do not specify the user-defined type while implementing the interface, then by default, it assumes them of type Object.<\/li>\n<\/ul>\n<h4>Java 8 Comparator Example: nullsFirst() and nullsLast() method<\/h4>\n<p>Here, we sort the list of elements that also contains null.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.comparators;\nimport java.util.*;\nclass Employee\n{\n  int id;\n  String name;\n  int salary;\n  public Employee(int id,String name,int salary)\n  {\n    this.id=id;\n    this.name=name;\n    this.salary=salary;\n  }\n  public int getID()\n  {\n    return id;\n  }\n  public void setID(int id)\n  {\n    this.id = id;\n  }\n  public String getName()\n  {\n    return name;\n  }\n\n  public void setName(String name)\n  {\n    this.name = name;\n  }\n\n  public int getSalary()\n  {\n    return salary;\n  }\n  public void setSalary(int age)\n  {\n    this.salary = age;\n  }\n}\n\/\/ Driver class\npublic class ComparatorInterfaceDemo\n{\n  public static void main(String args[]){\n    ArrayList&lt;Employee&gt; list=new ArrayList&lt;Employee&gt;();\n    list.add(new Employee(101,\"Rajeev\",26000));\n    list.add(new Employee(106,\"Anil\",21000));\n    list.add(new Employee(105,null,30000));\n                                 Comparator&lt;Employee&gt;cm1=Comparator.comparing(Employee::getName,Comparator.nullsFirst(String::compareTo));\n\n    Collections.sort(list,cm1);\n    System.out.println(\"Considers null to be less than non-null\");\n    for(Employee emp: list)\n    {\n      System.out.println(emp.id+\" \"+emp.name+\" \"+emp.salary);\n    }\n\n    Comparator&lt;Employee&gt;cm2=Comparator.comparing(Employee::getName,Comparator.nullsLast(String::compareTo));\n\n    Collections.sort(list,cm2);\n    System.out.println(\"\\nConsiders null to be greater than non-null\");\n    for(Employee emp: list){\n      System.out.println(emp.id+\" \"+emp.name+\" \"+emp.salary);\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Considers null to be less than non-null<br \/>\n105 null 30000<br \/>\n106 Anil 21000<br \/>\n101 Rajeev 26000<br \/>\nConsiders null to be greater than non-null<br \/>\n106 Anil 21000<br \/>\n101 Rajeev 26000<br \/>\n105 null 30000<\/div>\n<h3>Comparator vs Comparable in Java<\/h3>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td><b>Comparator<\/b><\/td>\n<td><b>Comparable<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">The Comparator sorts the attributes of different objects.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Comparable interface sorts the objects with the natural order.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">A Comparator interface compares the objects of two different classes.<\/span><\/td>\n<td><span style=\"font-weight: 400\">A Comparable interface compares \u201cthis\u201d reference of the specified object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">The Comparator is present in the<\/span><b> java.util <\/b><span style=\"font-weight: 400\">package.<\/span><\/td>\n<td><span style=\"font-weight: 400\">The Comparable is present in<\/span><b> java.lang<\/b><span style=\"font-weight: 400\"> package.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Comparator does not affect the original class.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Comparable affects or modifies the original class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Comparator provides compare() and equals() methods to sort the elements.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Comparable provides a compareTo() method to sort the elements.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Summary<\/h3>\n<p>Coming to the end of our article, we learned the concept of Comparator Interface in Java with its example. We also discussed Collections.Sort() with the help of a Java code and also got to know the rules which you should follow while using a Comparator interface in Java.<\/p>\n<p>Thank you for reading our article. Furthermore, if you have any queries related to Java Comparator Interface, do let us know by dropping a comment below.<\/p>\n<p>Happy Learning \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many situations when we often need to compare two values in our Java programs. Comparing primitive values like int, char, float, boolean, etc., is very easy and we can compare them using&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77486,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[1997,1998,1999,2000,2001],"class_list":["post-77178","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-comparator-interface-in-java","tag-comparator-vs-comparable-in-java","tag-java-comparator-interface","tag-java-comparator-interface-methods","tag-java-comparator-interface-rules"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Comparator Interface - Enhance your Knowledge with its Rules &amp; Methods - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn Comparator Interface in Java with its example. And explore its rules, methods with code examples &amp; difference b\/w Comparator Vs Comparable in Java.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Comparator Interface - Enhance your Knowledge with its Rules &amp; Methods - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn Comparator Interface in Java with its example. And explore its rules, methods with code examples &amp; difference b\/w Comparator Vs Comparable in Java.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-13T05:17:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/rules-for-java-comparator-interface.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Comparator Interface - Enhance your Knowledge with its Rules &amp; Methods - TechVidvan","description":"Learn Comparator Interface in Java with its example. And explore its rules, methods with code examples & difference b\/w Comparator Vs Comparable in Java.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/","og_locale":"en_US","og_type":"article","og_title":"Java Comparator Interface - Enhance your Knowledge with its Rules &amp; Methods - TechVidvan","og_description":"Learn Comparator Interface in Java with its example. And explore its rules, methods with code examples & difference b\/w Comparator Vs Comparable in Java.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-03-13T05:17:26+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/rules-for-java-comparator-interface.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java Comparator Interface &#8211; Enhance your Knowledge with its Rules &amp; Methods","datePublished":"2020-03-13T05:17:26+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/"},"wordCount":1002,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/rules-for-java-comparator-interface.jpg","keywords":["Comparator Interface in Java","Comparator vs Comparable in Java","Java Comparator Interface","Java Comparator Interface Methods","Java Comparator Interface Rules"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/","url":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/","name":"Java Comparator Interface - Enhance your Knowledge with its Rules &amp; Methods - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/rules-for-java-comparator-interface.jpg","datePublished":"2020-03-13T05:17:26+00:00","description":"Learn Comparator Interface in Java with its example. And explore its rules, methods with code examples & difference b\/w Comparator Vs Comparable in Java.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/rules-for-java-comparator-interface.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/03\/rules-for-java-comparator-interface.jpg","width":802,"height":420,"caption":"Rules for Java Comparator Interface"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-comparator-interface\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java Comparator Interface &#8211; Enhance your Knowledge with its Rules &amp; Methods"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77178"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77178\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77486"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}