For randomly shuffled numbers, let us create an integer list and add some numbers −List < Integer > list = new ArrayList < Integer > (); list.add(10); list.add(50); list.add(100); list.add(150); list.add(200);Now, shuffle the elements for random values −Collections.shuffle(list);Create an int array with the same number of elements in the above list −intlen = list.size(); int[] res = newint[len];Set the shuffled values in the new array −for (inti = 0; i < len; i++) { res[i] = list.get(i); }Example Live Demoimport java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { ... Read More
Here we will see what is re-declaration of global variables in C. Does C supports this or not. Let us see the following code to get the idea about it.Example#include int main(){ int a; int a = 50; printf("a is : %d", a); }Output[Error] redeclaration of 'a' with no linkageSo we can see that we cannot re-declare local variables. Now let us see what will be the output for global variables.Example#include int a; int a = 50; int main(){ printf("a is : %d", a); }Outputa is : 50So global variables are not creating any ... Read More
In this program we will see how to find the minimum digit from a two-digit number.Problem StatementWrite 8085 Assembly language program to find the minimum digit from a two-digit number. The number is stored at location 8000H, store the result at 8050H.DiscussionHere we are performing this task by using masking operation. Each digit takes one nibbles. We are masking the upper nibble by ANDing with 0FH (0000 1111). Store the lower nibble into another register. After that, we are taking the upper nibble. To get it, we are shifting the number to the right four times to convert lower nibble ... Read More
In this Program we need to implement binary search to find the existence of a search sequence in an array. The time complexity of Binary search is O(log(n)).Required steps and pseudocodesBegin BinarySearch() function has ‘arr’ the array of data and ‘n’ the number of values, start and end index, iteration count and b[0] be the element to be searched in the argument list. Increment the iteration counter and compare the item value with the a[mid]. If item < a[mid] choose first half otherwise second half to proceed further. Return index value to main. In main(), ... Read More
The with() method is used in Java to create Quintet Tuple.Let us first see what we need to work with JavaTuples. To work with Quintet class in JavaTuples, you need to import the following package −import org.javatuples.Quintet;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Quintet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Quintet; public class Demo { public static void main(String[] args) { ... Read More
Following example shows a JSP Expression printing date on the browser − A Comment Test Today's date: The above code will generate the following result −Today's date: 11-Sep-2010 21:24:25
The ResultSet interface provides the method named getBlob() to retrieve blob datatype from a table in the database. In addition to this, it also provides a method named getBinaryStream()Like getBlob() this method also accepts an integer representing the index of the column (or, a String value representing the name of the column) and retrieves the value at the specified column. The difference is unlike the getBlob() method (which returns a Blob object) this method returns an InputStream object which holds the contents of the blob datatype in the form of un-interpreted bytes.ExampleAssume we have created a table named MyTable in ... Read More
An immutable copy of a LocalTime object where some minutes are subtracted from it can be obtained using the minusMinutes() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of minutes to be subtracted and it returns the LocalTime object with the subtracted minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The current LocalTime is: " + lt); ... Read More
The skip() method of the LongStream class returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.The syntax is as follows −LongStream skip(long numEle)Here, numEle is the number of elements to be skipped.To use the LongStream class in Java, import the following package −import java.util.stream.LongStream;First, create a LongStrem and add some elements −LongStream longStream = LongStream.range(5000L, 5025l);Now, use the skip() method to skip the first n number of elements −longStream.skip(15) The following is an example to implement LongStream skip() method in Java −Example Live Demoimport java.util.stream.LongStream; public class Demo { ... Read More
To get distinct list of sub-document field values, you can use dot(.). The syntax is as follows −db.yourCollectionName.distinct("yourOuterFieldName.yourInnerFieldName");To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.getDistinctListOfSubDocumentFieldDemo.insertOne( ... { ... "StudentId": 101, ... "StudentPersonalDetails": [ ... { ... "StudentName": "John", ... "StudentAge":24 ... }, ... { ... ... Read More