Get Substring and Convert to Int in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

645 Views

Let’s say the following is our stream:Stream.of("u2", "h9", "s8", "l3")Now, map to get the substring:.map(s -> s.substring(1))Convert to int and find the minimum:.mapToInt(Integer::parseInt) .min()The following is an example to Map and get substring and convert to int:Exampleimport java.util.stream.Stream; public class Demo {    public static void main(String[] args) throws Exception {    Stream.of("u2", "h9", "s8", "l3")       .map(s -> s.substring(1))       .mapToInt(Integer::parseInt)       .min()       .ifPresent(System.out::println);    } }Output2

Using g++ to Compile Multiple C++ and Header Files

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

5K+ Views

To compile multiple files like file_name.h, or file_name.cpp at once, we can use the files like a list one after another. The syntax will be like this −g++ abc.h xyz.cppTo run the program, we can use this −./a.outExamplefloat area(float r){    return (3.1415*r*r); //area of a circle } float area(float l, float w){    return (l * w); //area of a rectangle }Example#include #include "area.h" using namespace std; main(){    cout

Java Connection GetStringFunctions Method with Example

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

296 Views

The getStringFunctions() method of the Connection interface retrieves the list of String functions supported by the current database. The names returned by this method are the Open CLI String function names.This method returns a String value holding the list of functions separated by commas (", ").To get the list of the String functions supported by the underlying database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the ... Read More

Execute Cube of Numbers in a Given Array using JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

To find the cubes of elements of given array we need to run a for loop to access each and every element and we need to use "=" operator to replace elements with their cubes.To get the desired values the below steps need to be followed.Steps1) Declared an array a = [1, 2, 3, 4, 5]2) For loop was introduced to access each and every element in the array(a[i]).3) Inside for loop "=" operator is used to replace the element with their cubic values(a[i]*a[i]*a[i]).so, from the above steps the output obtained will be 1, 8, 27, 64, 125.By following the ... Read More

Set Foreground Color for Different Words in a JTextPane

Smita Kapse
Updated on 30-Jul-2019 22:30:26

1K+ Views

To set the foreground color for different words, use the SimpleAttributeSet and StyleConstants class. With that, use StyledDocument class as well for different words style. For different words, use insertString().At first, create a new JTextPane -At first, create a new JTextPane: JTextPane pane = new JTextPane();Now, use the classes to set the style and color for some words −StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("", null); StyleConstants.setForeground(style, Color.red); StyleConstants.setBackground(style, Color.white); doc.insertString(doc.getLength(), "Game of Thrones ", style);Now, style some other words differently −StyleConstants.setForeground(style, Color.yellow); StyleConstants.setBackground(style, Color.gray); doc.insertString(doc.getLength(), "Season 8", style);The following is an example to set foreground color for different ... Read More

Create JMenuBar Component in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

206 Views

To create a JMenuBar component, use the JMenuBar class −JMenuBar menuBar = new JMenuBar();Now, create menus inside the MenuBar −JMenu fileMenu = new JMenu("File");Add the above menu to the MenuBar −menuBar.add(fileMenu);The following is an example to create a JMenuBar Component in Java −Examplepackage my; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class SwingDemo {    public static void main(final String args[]) {       JFrame frame = new JFrame("MenuBar Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JMenuBar menuBar = new JMenuBar();       JMenu fileMenu = new JMenu("File");       fileMenu.setMnemonic(KeyEvent.VK_F);   ... Read More

Check for Null in MongoDB

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

595 Views

We will use the Null type here. Following are the null types with the alias −TypeNumberAliasDouble1“double”String2“string”Object3“object”Array4“array”Binary data5“binData”Undefined6“undefined”ObjectId7“objectId”Boolean8“bool”Date9“date”Null10“null”Regular Expression11“regex”Following is the syntax for type 10 i.e. null −db.yourCollectionName.find({"yourFieldName":{ $type: 10 } });The above syntax will find only those documents which have null value. Let us first create a collection with documents −> db.mongoDbEqualDemo.insertOne({"Age":34}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7e9121a844af18acdffa3") } > db.mongoDbEqualDemo.insertOne({"Age":""}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7e9161a844af18acdffa4") } > db.mongoDbEqualDemo.insertOne({"Age":null}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7e9191a844af18acdffa5") } > db.mongoDbEqualDemo.insertOne({"Age":56}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7e91e1a844af18acdffa6") } > db.mongoDbEqualDemo.insertOne({}); ... Read More

Importance of java.lang Class in Java

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

451 Views

The java.lang.Class is one of the most important class in Java and it can provide several utility methods like getClass(), forName() which is used to find and load a class. It can also provide methods like Class.newInstance() which is the backbone of reflection and allow us to create an instance of a class without using new() operator.Importance of java.lang.ClassInstances of the class Class represent classes, interfaces,  enum and annotation in a running Java application.Whenever a java file is compiled, the compiler will insert a public, static, final field named Class of the type java.lang.Class into generated .class fileEach and every class exposes its code in the form of an ... Read More

Hide and Show HTML Elements in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

2K+ Views

Using Css style we can hide or show HTML elements in javascript. Css provides properties such as block and none to hide/show the HTML elements.Hiding an elementExampleIn the following example when the "Hideme" button has clicked the text in the paragraph tag has been disappeared as shown in the output.Live Demo    Using JavaScript to hide HTML elements.    

Convert Object Array to Integer Array in Java

Venkata Sai
Updated on 30-Jul-2019 22:30:26

7K+ Views

You can convert an object array to an integer array in one of the following ways −By copying each element from integer array to object array −Exampleimport java.util.Arrays; public class ObjectArrayToStringArray {    public static void main(String args[]){       Object[] objArray = {21, 58, 69, 33, 65};       int length = objArray.length;       int intArray[] = new int[length];       for(int i=0; i

Advertisements