Get Reverse Order Using Comparator in Java

Vikyath Ram
Updated on 30-Jun-2020 08:16:08

836 Views

The objects of a user defined class can be ordered using the Comparator interface in Java. The java.util.Collections.reverseOrder() method reverses the order of an element collection using a Comparator.A program that demonstrates this is given as follows −Exampleimport java.util.Arrays; import java.util.Collections; import java.util.Comparator; public class Demo {    public static void main(String args[]) throws Exception {       Comparator comparator = Collections.reverseOrder(); { "John", "Amy", "Susan", "Peter" };       int n = str.length;       System.out.println("The array elements are: ");       for (int i = 0; i < n; i++) {       ... Read More

Filter Specific Values from a MongoDB Document

AmitDiwan
Updated on 30-Jun-2020 08:15:02

581 Views

To filter specific values, use $filter in MongoDB. Let us create a collection with documents −> db.demo751.insertOne( ...    { ...       _id: 101, ...       details: [ ...          { Name: "Robert", id:110, Age:21}, ...          { Name: "Rae", id:110, Age:22}, ...          {Name: "Ralph", id:116, Age:23} ...       ] ...    } ... ); { "acknowledged" : true, "insertedId" : 101 }Display all documents from a collection with the help of find() method −> db.demo751.find().pretty();This will produce the following output −{    "_id" ... Read More

Using Set in Python for Pangram Checking

karthikeya Boyini
Updated on 30-Jun-2020 08:14:53

383 Views

In this article, we will learn how to determine whether a string is “pangram” or not in Python 3.x. Or earlier. A pangram string contains every letter in the list of English language alphabets . Let us look at the illustration below −Provided Input: str = 'This is the python blog on Tutorial point' Desired Output: No Provided Input : str='I want to contribute to a 'dxyzwuvghlkfmq' open source project' Desired Output: YesBy definition, a perfect pangram includes every letter of the ‘26 English alphabets’ exactly once. This tutorial doesn’t include the concept of ‘perfect pangram’.Now Let’s look at the ... Read More

Perform Binary Search in Java Using Collections.binarySearch

Arushi
Updated on 30-Jun-2020 08:14:53

341 Views

Binary Search can be performed in Java using the method java.util.Collections.binarySearch(). This method requires two parameters i.e. the list in which binary search is to be performed and the element that is to be searched. It returns the index of the element if it is in the list and returns -1 if it is not in the list.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String args[]) {       List aList = new ArrayList();       aList.add("James");       aList.add("George"); ... Read More

vars() Function in Python

Syed Javed
Updated on 30-Jun-2020 08:13:57

726 Views

vars() function belongs to the collection of inbuilt functions provided by the Python standard library. It returns the __dic__ attribute of an associated object to the console.Syntaxvars(object)Return TypeParametersvars() function accepts only one parameter. It takes an object as its parameter which can be any module, class or any object having __dict__ attribute associated with it.This parameter is optional in nature. In case the function is used without parameters A dictionary containing local symbol table is displayed.Exceptions InvolvedIf the argument passed doesn’t match the attribute, it raises the TypeError exception.ScopeVars() acts like locals() method when no argument is passed.The locals() method ... Read More

Sort a List in Java

Jai Janardhan
Updated on 30-Jun-2020 08:13:41

146 Views

A list can be sorted in ascending order using the java.util.Collections.sort() method. This method requires a single parameter i.e. the list to be sorted and no value is returned. The ClassCastException is thrown by the Collections.sort() method if there are mutually incomparable elements in the list.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String args[]) {       List aList = new ArrayList();       aList.add("James");       aList.add("Harry");       aList.add("Susan");       aList.add("Emma");       aList.add("Peter"); ... Read More

Get Max Values for Distinct Elements in MongoDB

AmitDiwan
Updated on 30-Jun-2020 08:12:49

723 Views

To get max values for distinct elements, use $sort and $group in MongoDB aggregate(). Let us create a collection with documents −> db.demo750.insertOne({id:101, value:50}); {    "acknowledged" : true,    "insertedId" : ObjectId("5eae74b2a930c785c834e566") } > db.demo750.insertOne({id:102, value:40}); {    "acknowledged" : true,    "insertedId" : ObjectId("5eae74c8a930c785c834e567") } > db.demo750.insertOne({id:101, value:110}); {    "acknowledged" : true,    "insertedId" : ObjectId("5eae74dba930c785c834e568") }Display all documents from a collection with the help of find() method −> db.demo750.find();This will produce the following output −{ "_id" : ObjectId("5eae74b2a930c785c834e566"), "id" : 101, "value" : 50 } { "_id" : ObjectId("5eae74c8a930c785c834e567"), "id" : 102, "value" : 40 } ... Read More

Simplex Stop-and-Wait Protocol for a Noisy Channel

George John
Updated on 30-Jun-2020 08:12:32

15K+ Views

Simplex Stop – and – Wait protocol for noisy channel is data link layer protocol for data communications with error control and flow control mechanisms. It is popularly known as Stop – and –Wait Automatic Repeat Request (Stop – and –Wait ARQ) protocol. It adds error control facilities to Stop – and – Wait protocol.This protocol takes into account the facts that the receiver has a finite processing speed and that frames may get corrupted while transmission. If data frames arrive at the receiver’s end at a rate which is greater than its rate of processing, frames can be dropped ... Read More

Update Each Field of Documents in MongoDB Collection with a Formula

AmitDiwan
Updated on 30-Jun-2020 08:11:21

237 Views

To update each field of documents in collection with a formula, use MongoDB update(). Let us create a collection with documents −> db.demo749.insertOne({"details":[{"id":1, a:10}, {"id":2, a:5}, {"id":3, a:20}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5eae6fb0a930c785c834e565") }Display all documents from a collection with the help of find() method −> db.demo749.find().pretty();This will produce the following output −{    "_id" : ObjectId("5eae6fb0a930c785c834e565"),    "details" : [       {          "id" : 1,          "a" : 10       },       {          "id" : 2,     ... Read More

Maximum Size of a Document in MongoDB

AmitDiwan
Updated on 30-Jun-2020 08:08:46

480 Views

The document is a record in a collection. Each document has the limitation of 16 MB size. The document is wrapped inside the curly bracket ({}).Let us create a collection with documents −> db.demo748.insertOne({_id:101, Name:"Chris", Age:21}); { "acknowledged" : true, "insertedId" : 101 } > db.demo748.insertOne({_id:102, Name:"Bob", Age:20}); { "acknowledged" : true, "insertedId" : 102 } > db.demo748.insertOne({_id:103, Name:"David", Age:23}); { "acknowledged" : true, "insertedId" : 103 } > db.demo748.insertOne({_id:104, Name:"Sam", Age:19}); { "acknowledged" : true, "insertedId" : 104 }Display all documents from a collection with the help of find() method −> db.demo748.find();This will produce the following output −{ "_id" ... Read More

Advertisements