AmitDiwan has Published 11365 Articles

Program to convert a Set to Stream in Java using Generics

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 07:42:37

119 Views

Let’s say the following is our Set −Set set = new HashSet(Arrays.asList(15, 40, 60, 90, 120, 150, 200));Now, create a method to convert the above set to stream.StreamstreamOfInteger = convertSet(set);The method −private static Stream convertSet(Set set) {    return set.stream(); }ExampleFollowing is the program to convert a Set to ... Read More

Program to convert a Map to a Stream in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 07:40:46

409 Views

At first, create a Map and set values −Map map = new HashMap(); map.put(1, "Kevin"); map.put(2, "Ryan"); map.put(3, "Nathan"); map.put(4, "Ricky"); map.put(5, "Shane"); map.put(6, "Adam");Now, convert the Map to Stream −Stream stream = map.entrySet().stream(); System.out.println("Stream (Map to Stream) = "+ Arrays.toString(stream.toArray()));ExampleFollowing is the program to convert a Map to a ... Read More

The String in Switch Case in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 07:35:00

207 Views

The introduction of Java 7 enhanced the switch case i.e. it support string as well.At first, set a string −String department = "AKD05";Now, use the same string in switch as shown below −switch(department)ExampleNow, check for every string using case as we normally do while using SWITCH CASE. Following is an ... Read More

Stream.distinct() in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 07:32:21

491 Views

The distinct() method of the stream class returns a stream consisting of the distinct elements of this stream. The syntax is as following −Stream distinct()ExampleFollowing is an example to implement the distinct() method in the Stream class −import java.util.*; public class Demo {    public static void main(String[] args) { ... Read More

Stream.concat() in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 07:30:33

167 Views

The concat() method of the Stream class in Java creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream. The syntax is as follows −concat(Stream

Copy values of one column to another using INSERT and SELECT in a single MySQL query

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 06:24:27

626 Views

Let us first create a table −mysql> create table DemoTable1 (    Name varchar(100),    Gender ENUM('MALE', 'FEMALE') ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('Chris', 'Male'); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

How to implement HAVING LENGTH(field) in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Sep-2019 14:14:14

95 Views

Let us first create a table −mysql> create table DemoTable (    Title text ); Query OK, 0 rows affected (0.39 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Introduction to ... Read More

Set options while creating a MySQL table. Display the same options as well

AmitDiwan

AmitDiwan

Updated on 24-Sep-2019 14:10:19

158 Views

To display, use DESC command or information_schema.columns. Let us first create a table and set options −mysql> create table DemoTable (    Color SET('RED', 'GREEN', 'BLUE', 'YELLOW') ); Query OK, 0 rows affected (0.47 sec)Case 1Here is the query to get the list of available options for SET using the ... Read More

Inserting random numbers into a table in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Sep-2019 14:08:08

810 Views

To insert random numbers, use RAND() function from MySQL. Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 ... Read More

Delete a record with tablename.columnname= value in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Sep-2019 14:04:14

95 Views

To delete a record in the required way, the syntax is as follows −delete from yourTableName where yourTableName .yourColumnName=yourValue;Let us first create a table −mysql> create table DemoTable (    StudentName varchar(100),    StudentAge int ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert ... Read More

Advertisements