Articles on Trending Technologies

Technical articles with clear explanations and examples

Format MySQL CURRENT_TIMESTAMP to AM & PM?

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 574 Views

To format, use DATE_FORMAT(). Let us first create a tablemysql> create table DemoTable (    LoginTime time ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('13:10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('20:08'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('10:55'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('16:40'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+ | ...

Read More

How to remove only the first word from columns values with a MySQL query?

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 743 Views

To remove only the first word from column values, use substring(). Following is the syntax −select substring(yourColumnName, locate(' ', yourColumnName)+1) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable (    Title text ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java in Depth'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable values('C++ is an object oriented programming language'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('MySQL is a relational database'); Query OK, 1 row affected (0.17 ...

Read More

Remove 20% from stored price in MySQL field, using SQL query?

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 182 Views

Let’s say the stored price is inclusive of 20% sales tax. Now, let us first create a table −mysql> create table DemoTable (    Price int ); Query OK, 0 rows affected (1.09 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select ...

Read More

Convert Iterator to Iterable in Java

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 1K+ Views

Let’s say the following is our Iterator with Integer values −Iteratoriterator = Arrays.asList(20, 40, 60, 80, 100, 120, 150, 200).iterator();Now, convert the Iterator to Iterable −Iterableiterable = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0),false).collect(Collectors.toList());ExampleFollowing is the program to convert Iterator to Iterable in Java −import java.util.*; import java.util.stream.Collectors; import java.util.stream.StreamSupport; public class Demo {    public static void main(String[] args) {       Iteratoriterator = Arrays.asList(20, 40, 60, 80, 100, 120, 150, 200).iterator();       Iterableiterable = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false).collect(Collectors.toList());       System.out.println("Iterable = ");       iterable.forEach(System.out::println);    } }OutputIterable = 20 40 60 80 100 120 150 200

Read More

How I can show JavaScript alert box in the middle of the screen?

Giri Raju
Giri Raju
Updated on 25-Sep-2019 2K+ Views

To show the JavaScript alert box in the middle, you need to use the custom alert box. Under that, style it accordingly and position it to the center. Use the "top" and "left" CSS properties to achieve this. Set them as 50%, but as you can see a button below, use the property to 40% to align it with the button: Example                 function functionAlert(msg, myYes) {       var confirmBox = $("#confirm");       confirmBox.find(".message").text(msg);       confirmBox.find(".yes").unbind().click(function() {         confirmBox.hide();       });       confirmBox.find(".yes").click(myYes);       confirmBox.show();      }              #confirm {       display: none;       background-color: #F3F5F6;       color: #000000;       border: 1px solid #aaa;       position: ...

Read More

Convert an Iterator to Stream in Java

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 469 Views

At first, set an Interator −Iteratoriterator = Arrays.asList(50, 100, 200, 400, 500, 1000).iterator();Now, we have used stream −Streamstream = convertIterator(iterator);Above, the method convertIterator() is used for conversion. Following is the method −public static Stream convertIterator(Iterator iterator) {    return StreamSupport.stream(((Iterable) () -> iterator).spliterator(), false); }ExampleFollowing is the program to convert an Iterator to Stream in Java −import java.util.stream.*; import java.util.*; public class Demo {    public static Stream    convertIterator(Iterator iterator) {       return StreamSupport.stream(((Iterable) () -> iterator).spliterator(), false);    }    public static void main(String[] args) {       Iteratoriterator = Arrays.asList(50, 100, 200, ...

Read More

Convert a Set of String to a comma separated String in Java

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 1K+ Views

Let us first create a set with string values −Setset = new HashSet(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six"));Now, convert it to a comma separated string using String.join() −String str = String.join(", ", set);ExampleFollowing is the program to convert set of string to a comma separated string in Java −import java.util.*; public class Demo {    public static void main(String args[]) {       Setset = new HashSet(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six"));       System.out.println("Set = " + set);       String str = String.join(", ", set);       System.out.println("Comma separated String: "+ str);    } ...

Read More

Convert a List of String to a comma separated String in Java

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 625 Views

At first, let’s say the following is our List of String −List myList = new ArrayList(Arrays.asList("One", "Two", "Three", "Four"));Now, convert this to a comma separated string using String.join()String str = String.join(", ", myList);ExampleFollowing is the program to convert List of String to a comma separated String in Java −import java.util.*; public class Demo {    public static void main(String args[]) {       List myList = new ArrayList(Arrays.asList("One", "Two", "Three", "Four"));       System.out.println("List = " + myList);       // comma separated       String str = String.join(", ", myList);       System.out.println("String (Comma ...

Read More

Conversion of Java Maps to List

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 224 Views

At first, let us create a Java Map and initialize −Map map = new HashMap(); map.put(1, "Tom"); map.put(2, "John"); map.put(3, "Kevin"); map.put(4, "Jacob"); map.put(5, "Ryan");Now, convert the Map to List −ArrayList key = new ArrayList(map.keySet()); ArrayList value = new ArrayList(map.values());ExampleFollowing is the program to convert Maps to List in Java −import java.util.HashMap; import java.util.ArrayList; import java.util.Map; public class Demo {    public static void main(String args[]) {       Map map = new HashMap();       map.put(1, "Tom");       map.put(2, "John");       map.put(3, "Kevin");       map.put(4, "Jacob");       map.put(5, "Ryan"); ...

Read More

Program to convert Boxed Array to Stream in Java

AmitDiwan
AmitDiwan
Updated on 25-Sep-2019 221 Views

A boxed array is an array which is defined in the form of an object, instead of the primitives.ExampleFollowing is the program to convert Boxed Array to Stream in Java −import java.util.*; import java.util.stream.*; public class Demo {    public static void main(String args[]) {       String arr[] = { "Laptop", "Mobile", "Notebook", "Desktop" };       System.out.println("Array = "+ Arrays.toString(arr));       Streams = Stream.of(arr);       System.out.println("Stream (array to stream) = "+ Arrays.toString(s.toArray()));    } }OutputArray = [Laptop, Mobile, Notebook, Desktop] Stream (array to stream) = [Laptop, Mobile, Notebook, Desktop]

Read More
Showing 55781–55790 of 61,248 articles
Advertisements