Map to Add String Value to Each Element in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

836 Views

Let’s say the following is our String List −List list = Arrays.asList("Football", "Basketball", "Hockey", "Cricket", "Fencing");Now, map to add string to each element −List str = list.stream().map(name -> "Sports " + name + " Outdoor")    .collect(Collectors.toList());Above, we have added “Sports” and “Outdoor” strings to each element.The following is an example to Map and add string value to each element in Java −Exampleimport java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Demo {    public static void main(String[] args) {       List list = Arrays.asList("Football", "Basketball", "Hockey", "Cricket", "Fencing");       List str = list.stream().map(name -> "Sports " ... Read More

Make a Background 25% Transparent on iOS

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

Apple provides backgroundColor which is an instance property, Changes to this property can be animated. The default value is nil, which results in a transparent background color.To make background 25% transparent we should  set the view to the UIColor with alpha 0.25view.backgroundColor = UIColor(white: 1, alpha: 0.25)You can write the following code in your ViewController’s viewDidLoad method.Your code should look like below.override func viewDidLoad() {    super.viewDidLoad()    view.backgroundColor = UIColor(white: 1, alpha: 0.25) }

Format Text in JTextPane using Java

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

463 Views

To format text in JTextPane, use the SimpleAttributeSet and StyleConstants class. This allows you to set the style of text, background color, foreground color, etc.At first, create a new JTextPane −JTextPane pane = new JTextPane();Now, use the classes to set the style and color −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setItalic(attributeSet, true); StyleConstants.setForeground(attributeSet, Color.black); StyleConstants.setBackground(attributeSet, Color.orange);Now, apply the set to the pane −pane.setCharacterAttributes(attributeSet, true);The following is an example to format text in JTextPane −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; public class SwingDemo {    public static void ... Read More

Detect Click on HTML Button through JavaScript in Android WebView

George John
Updated on 30-Jul-2019 22:30:26

4K+ Views

This example demonstrate about How to lock the Android device programmatically.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml     Step 3 − Add the following code to assets/page.html           First name:       Last name:                function getValues() {             document.getElementById("btnOK").value =             document.getElementById("txtfname").value+"         ... Read More

Explain Polymorphism in PHP

Alok Prasad
Updated on 30-Jul-2019 22:30:26

12K+ Views

To begin with, Polymorphism is gotten from the Greek words Poly (which means many) and morphism (which meaning forms).Polymorphism portrays an example in object-oriented programming where methods in various classes that do similar things should have a similar name. Polymorphism is essentially an OOP pattern that enables numerous classes with different functionalities to execute or share a commonInterface. The usefulness of polymorphism is code written in different classes doesn't have any effect which class it belongs because they are used in the same way. In order to ensure that the classes do implement the polymorphism guideline, we can pick between ... Read More

MySQL Query to Get Current Date from List of Dates

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

146 Views

For the current day, you can use CURDATE() method. Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (1.35 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-14' ); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('2019-06-15'); Query OK, 1 row affected (0.64 sec) mysql> insert into DemoTable values('2019-06-16'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2018-01-16'); Query OK, 1 row affected (0.29 sec) mysql> insert into ... Read More

HTML DOM Input URL Placeholder Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

185 Views

The HTML DOM Input URL placeholder property sets/returns a string generally used to give hints to user of what the input text will look like.SyntaxFollowing is the syntax −Returning string valueinputURLObject.placeholderSetting placeholder to stringValueinputURLObject.placeholder = stringValueExampleLet us see an example of Input URL placeholder property − Live Demo Input URL placeholder    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } ... Read More

Parameter Passing Techniques in C/C++

Samual Sam
Updated on 30-Jul-2019 22:30:26

6K+ Views

In C we can pass parameters in two different ways. These are call by value, and call by address, In C++, we can get another technique. This is called Call by reference. Let us see the effect of these, and how they work.First we will see call by value. In this technique, the parameters are copied to the function arguments. So if some modifications are done, that will update the copied value, not the actual value.Example#include using namespace std; void my_swap(int x, int y) {    int temp;    temp = x;    x = y;    y = ... Read More

Java SQL Timestamp toString() Method with Example

Rishi Raj
Updated on 30-Jul-2019 22:30:26

7K+ Views

The toString() method of the java.sql.Timestamp class returns the JDBC escape format of the time stamp of the current Timestamp object as String variable.i.e. using this method you can convert a Timestamp object to a String.//Retrieving the Time object Timestamp timestampObj = rs.getTimestamp("DispatchTimeStamp"); //Converting the Time object to String format String time_stamp = timestampObj.toString();ExampleLet us create a table with the name dispatches_data in MySQL database using CREATE statement as shown below:CREATE TABLE dispatches_data(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchTimeStamp timestamp,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches_data table using INSERT statements:insert into ... Read More

Set a Specific Date Format in MySQL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

146 Views

To set a pecific date format, you need to use DATE_FORMAT() in MySQL. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ArrivalDate date ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ArrivalDate) values('2019-01-31'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-04-26'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-03-01'); Query OK, 1 row affected (0.13 sec)Display all ... Read More

Advertisements