Request Location Permission at Run Time in Android

Azhar
Updated on 01-Jul-2020 07:31:56

5K+ Views

This example demonstrates how do I request Location permission in android.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 src/MainActivity.javaimport android.Manifest; import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       if ... Read More

Remove All Elements from a Map in JavaScript

vineeth.mariserla
Updated on 01-Jul-2020 07:26:13

1K+ Views

The map is basically a collection of elements where each element is stored as a Key, value pair. It can hold both objects and primitive values as either a key or a value. When we iterate over the map object it returns the key, value pair in the same order as inserted. The map has provided a method called map.clear() to remove the values inside a map. This method will remove every key/value pair and make the map totally empty.syntaxmap.clear(obj);map.obj() takes an object as a parameter and removes each and every value so as to make it empty.Example-1In the following example, a map is created ... Read More

Redirection in PHP

AmitDiwan
Updated on 01-Jul-2020 07:19:49

7K+ Views

The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client).Syntax of header functionheader( $header_value, $replace_value, $http_response_code)Following are the parameters −The ‘header_value’ in the function is used to store the header string.The ‘replace_value’ parameter stores the value that needs to be replaced.The ‘response_code’ is used to store the HTTP response code.ExampleThe website to which the page needs to be redirected is specified in the header function.

List Methods in Python: in, not in, len, min, max

Pavitra
Updated on 01-Jul-2020 07:19:09

26K+ Views

In this article, we will learn about various types of list methods available to us in Python 3.x. Or earlier. These operators allow us to perform the basic operations on the list content.In & Not in operators“in” operator  − This operator is used to check whether an element is present in the passed list or not. Returns true if the element is present in the list otherwise returns false.“not in” operator  − This operator is used to check whether an element is not present in the passed list or not. Returns true if the element is not present in the ... Read More

Internal Working of the foreach Loop in PHP

AmitDiwan
Updated on 01-Jul-2020 07:18:25

277 Views

The ‘foreach’ loop in PHP helps in accessing key value pairs within an array. The ‘foreach’ loop works with arrays only, with the advantage that a loop counter wouldn’t need to be initialized. In addition to this, no condition needs to be set that would be needed to exit out of the loop. The ‘foreach’ loop implicitly does this too.Example Live DemoOutputJoe Hannah Paul SannaAn array of string values is defined and the foreach loop is used to access every element inside the array by giving a variable name. The ‘echo’ is used to display every element of the array on ... Read More

Iterate Over a Dictionary in Python

Pavitra
Updated on 01-Jul-2020 07:15:00

321 Views

In this article, we will learn about iteration/traversal of a dictionary in Python 3.x. Or earlier.A dictionary is an unordered sequence of key-value pairs. Indices can be of any immutable type and are called keys. This is also specified within curly braces.Method 1 − Using iterables directlyExampledict_inp = {'t':'u', 't':'o', 'r':'i', 'a':'l', 's':'p', 'o':'i', 'n':'t'} # Iterate over the string for value in dict_inp:    print(value, end='')OutputtrasonMethod 2 − Using iterables for values of the dictionaryExampledict_inp = {'t':'u', 't':'o', 'r':'i', 'a':'l', 's':'p', 'o':'i', 'n':'t'} # Iterate over the string for value in dict_inp.values():    print(value, end='')OutputoilpitMethod 3 − ... Read More

Check If a String Contains a Specific Substring

AmitDiwan
Updated on 01-Jul-2020 07:14:54

767 Views

To check if a string contains a specific substring, the ‘strlen’ and ‘strpos’ functions can be used. The ‘strlen’ gives the entire length of the string. The function ‘strpos’ finds the position wherein the substring occurs first in the string.Example Live DemoOutputThe substring is present within the string.Two strings are defined and the position of the second string in the first string is checked with the help of the ‘strpos’ function and compared with the length of the first string. Relevant message is displayed on the console.

Iterate Over a List in Python

Pavitra
Updated on 01-Jul-2020 07:13:07

443 Views

In this article, we will learn about iterating/traversing over a list in Python 3.x. Or earlier.A list is an ordered sequence of elements. It is a non-scalar data structure and mutable in nature. A list can contain distinct data types in contrast to arrays storing elements belonging to the same data types.Method 1 − Using iterable without indexExamplelist_inp = ['t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o', 'i', 'n', 't'] # Iterate over the list for value in list_inp:    print(value, end='')Method 2 − Using general way via indexExamplelist_inp = ['t', 'u', 't', 'o', 'r', 'i', ... Read More

Iterate Over a Set in Python

Pavitra
Updated on 01-Jul-2020 07:11:50

3K+ Views

In this article, we will learn about iterating/traversing over a set in Python 3.x. Or Earlier.It is an unordered collection of objects without any duplicates. This can be done by enclosing all the elements within curly braces. We can also form sets by using type casting via a keyword “set”.Method 1 − Using iterables without indexesExampleset_inp = {'t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o', 'i', 'n', 't'} # Iterate over the set for value in set_inp:    print(value, end='')Method 2 − Using indexed access by converting to list typeExampleset_inp = list({'t', 'u', 't', 'o', 'r', ... Read More

Late Static Bindings in PHP

AmitDiwan
Updated on 01-Jul-2020 07:11:33

1K+ Views

The basic idea behind late static bindings is that the concept of inheritance and the concept of ‘self’ keyword don’t follow the same rules. For example, a method ‘fun’ in parent class called in the child class won’t make ‘self’ refer to the child (as expected).The concept of late static bindings brings in a new keyword ‘static’, which when used, binds the function to the runtime class, or the class where the function was first used. In addition to this, any static function or variable is usually executed during runtime and not during compile time. Hence, if a value needs ... Read More

Advertisements