Pass Function as Parameter in Java

Prabhas
Updated on 17-Jun-2020 11:36:16

5K+ Views

Yes. From Java 8 onwards, we can do so using method references.Method references help to point to methods by their names. A method reference is described using "::" symbol. A method reference can be used to point the following types of methods −Static methodsInstance methodsConstructors using new operator (TreeSet::new)Method Reference ExampleCreate the following Java program using any editor of your choice in, say, C:\> JAVA.Java8Tester.java Live Demo import java.util.List; import java.util.ArrayList; public class Java8Tester {    public static void main(String args[]) {       List names = new ArrayList(); names.add("Mahesh");       names.add("Suresh");       names.add("Ramesh");       ... Read More

Add Information with Bootstrap 4 Card

Alex Onsman
Updated on 17-Jun-2020 11:35:57

146 Views

To add information to a card in Bootstrap 4, use the bg-info class.Use the card class with the bg-info class:Add the card body after that using the card-body class −   Demo Text You can try to run the following code to add information −ExampleLive Demo       Bootstrap Example                         Festival Celebration       Reach till 5PM  

Set Warning Action with Orange Outlined Bootstrap 4 Button

Alex Onsman
Updated on 17-Jun-2020 11:34:25

228 Views

Set orange outline for a Bootstrap 4 button, using the btn-outline-warning class and indicate warning action.The following includes the orange outline on a button −   Rejected The class is added just as any other class added to any element in Bootstrap.  For a Bootstrap button, I used the element.You can try to run the following code to implement the btn-outline-warning class −ExampleLive Demo       Bootstrap Example                       College Placements   Selected Students   Rejected Students   Result Awaited List of selected and rejected students: Selected Rejected

Return 2 Values from a Java Method

seetha
Updated on 17-Jun-2020 11:32:59

797 Views

A method can give multiple values if we pass an object to the method and then modifies its values. See the example below −Examplepublic class Tester {    public static void main(String[] args) {       Model model = new Model();       model.data1 = 1;       model.data2 = 2;       System.out.println(model.data1 + ", " + model.data2);       changeValues(model);       System.out.println(model.data1 + ", " + model.data2);    }    public static void changeValues(Model model) {       model.data1 = 100;       model.data2 = 200;    } } class Model {    int data1;    int data2; }Output1, 2 100, 200

Indicate Danger with Red Outlined Bootstrap 4 Button

Alex Onsman
Updated on 17-Jun-2020 11:30:58

167 Views

Use the btn-outline-danger class in Bootsrap 4 to indicate danger with red outlined button.The following is an example to set a button that indicates danger with red outline −   Danger The class is added using the btn and btn-outline-danger class in Bootstrap −class="btn btn-outline-danger”Let us see an example to implement the btn-outline-danger class −ExampleLive Demo       Bootstrap Example                         Animals   Animals are in danger. To know what, you need to click below:   Danger

Filter an Array in Java

Ali
Ali
Updated on 17-Jun-2020 11:30:58

7K+ Views

You can use List.removeAll() method to filter an array. exampleimport java.util.ArrayList; import java.util.List; public class Tester {    public static void main(String[] args) {       List list = new ArrayList();       list.add("A");       list.add("B");       list.add("C");       list.add("D");       list.add("E");       list.add("F");       list.add("G");       list.add("H");       List filters = new ArrayList();       filters.add("D");       filters.add("E");       filters.add("F");       System.out.println("Original List " + list);       list.removeAll(filters);       System.out.println("Filtered List ... Read More

Create Python Dictionary from JSON Input

George John
Updated on 17-Jun-2020 11:22:57

1K+ Views

You can parse JSON files using the json module in Python. This module parses the json and puts it in a dict. You can then get the values from this like a normal dict. For example, if you have a json with the following content{    "id": "file",    "value": "File",    "popup": {       "menuitem": [          {"value": "New", "onclick": "CreateNewDoc()"},          {"value": "Open", "onclick": "OpenDoc()"},          {"value": "Close", "onclick": "CloseDoc()"}       ]    } }You can load it in your python program and loop over ... Read More

Remove Float from an Element in Bootstrap

Alex Onsman
Updated on 17-Jun-2020 11:22:04

416 Views

Use the float-none class in Bootstrap to remove float from an element.The default for a text is always left; therefore removing float will place the text on the left −You can try to run the following code to remove float from an element −ExampleLive Demo       Bootstrap Example                             Demo           This text is on the left (on small screen).       This text is on the left (on medium screen).       This text is on the left (float removed).       This text is on the left (on extra large screen).       This text is on the left (float removed).    

Stretch a Flex Item on Different Screens in Bootstrap 4

Ricky Barnes
Updated on 17-Jun-2020 11:18:03

134 Views

To stretch a flex item on different screens in Bootstrap 4, use the .align-self-*-stretch class.To strect in on different screens, you need to use align-self-sm-stretch, align-self-md-stretch, align-self-lg-stretch, etc. Below is an example for small screen size −   A-one   B-one   C-one   D-one You can try to run the following code to stretch a flex item on different screen sizes −ExampleLive Demo       Bootstrap Example                             Align Specific Flex Item and Stretch           A-one       B-one       C-one       D-one       Small Screen Size       A-one     B-one     C-one     D-one     Medium Screen Size         A-one     B-one     C-one     D-one     Large Screen Size         A-one     B-one     C-one     D-one      

Search Python Dictionary for Matching Key

Ankith Reddy
Updated on 17-Jun-2020 11:17:59

4K+ Views

If you have the exact key you want to find, then you can simply use the [] operator or get the function to get the value associated with this key. For example,Examplea = {    'foo': 45,    'bar': 22 } print(a['foo']) print(a.get('foo'))OutputThis will give the output:45 45ExampleIf you have a substring that you want to search in the dict, you can use substring search on the keys list and if you find it, use the value. For example,a = {    'foo': 45,    'bar': 22 } for key in a.keys():    if key.find('oo') > -1:       print(a[key])OutputThis will give the output45

Advertisements