Ankith Reddy has Published 1070 Articles

LongStream anyMatch() method in Java

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

133 Views

The anyMatch() method of the LongStream class in Java returns whether any elements of this stream match the provided predicate.The syntax is as follows.boolean anyMatch(LongPredicate predicate)Here, the parameter predicate is the stateless predicate to apply to elements of this stream. The LongPredicate represents a predicate of one long-valued argument.To use ... Read More

Find oldest/ youngest post in MongoDB collection?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

904 Views

To find oldest/youngest post in MongoDB collection, you can use sort(). Let’s say you have a document with a field “UserPostDate” and you need to get the oldest and youngest post. For that, Let us first create a collection with documents>db.getOldestAndYoungestPostDemo.insertOne({"UserId":"Larry@123", "UserName":"Larry", "UserPostDate":new ISODate('2019-03-27 12:00:00')}); {    "acknowledged" : true, ... Read More

Lambda expression in C++

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

406 Views

C++ STL includes useful generic functions like std::for_each. Unfortunately they can also be quite cumbersome to use, particularly if the functor you would like to apply is unique to the particular function. So this function that you'll create will be in that namespace just being used at that one place. ... Read More

Select text after last slash in MySQL?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

882 Views

You need to use substring_index() function from MySQL to select text.The syntax is as followsSELECT substring_index(yourColumnName, '/', -1) AS anyAliasName FROM yourTableName;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table selectTextAfterLastSlashDemo - > ( ... Read More

How to update MongoDB collection using $toLower?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

572 Views

There is a $toLower operator in MongoDB to be used as part of aggregate framework. But, we can also use the for loop to iterate over the specific field and update one by one.Let us first create a collection with documents> db.toLowerDemo.insertOne({"StudentId":101, "StudentName":"John"}); {    "acknowledged" : true,    "insertedId" ... Read More

MySQL check for crashed table?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

594 Views

If a table is crashed that means your ENGINE is NULL or empty. The syntax is as follows to check for crashed table.SHOW TABLE STATUS FROM yourDatabaseName;Let us implement the above syntax to check for crashed table Here, our database name is ‘test3’ with some tablesmysql> show table status from ... Read More

Print system time in C++

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

462 Views

The C++ standard library does not provide a proper date type. C++ inherits the structs and functions for date and time manipulation from C. To access date and time related functions and structures, you would need to include header file in your C++ program.There are four time-related types: clock_t, ... Read More

How to operate on all databases from the MongoDB shell?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

128 Views

To operate on all databases from MongoDB shell, you can use listDatabases along with adminCommand().Let’s say we are using a sample database “test”. At first, check the current database with the help of db command.Following is the query to get the current database> db;This will produce the following outputTestFollowing is ... Read More

MySQL ORDER BY Date field not in date format?

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

624 Views

The following is the syntax to order by date field which is not in date formatselect *from yourTableName order by STR_TO_DATE(yourColumnName, '%d/%m/%Y') DESC;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table orderByDateFormatDemo    -> (    -> Id ... Read More

IntStream toArray() method in Java

Ankith Reddy

Ankith Reddy

Updated on 30-Jul-2019 22:30:25

209 Views

The toArray() method returns an array containing the elements of this stream.Set the elements in the stream with the IntStream class of() method.IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);Now, display an array with the elements of this stream using the toArray() method.int[] myArr = stream.toArray();The following is ... Read More

Advertisements