How to get battery level and state in Android?

Arjun Thakur
Published on 30-Jan-2019 12:37:07
This example demonstrates how to get battery level and state 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.<?xml version = "1.0" encoding = ... Read More

Java Program to remove a key from a TreeMap only if it is associated with a given value

karthikeya Boyini
Published on 30-Jan-2019 12:47:50
Use the remove() method to remove a key from a TreeMap only if it is associated with a given value. Let us first create a TreeMap and add some elements −TreeMap<Integer, String> m = new TreeMap<Integer, String>(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada");To remove a key, ... Read More

Remove a key from TreeMap in Java

Samual Sam
Published on 30-Jan-2019 12:41:14
Use the remove() method to remove a key from TreeMap.Let us first create a TreeMap and add some elements −TreeMap<Integer, String> m = new TreeMap<Integer, String>(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada");Let us remove a key now. Here, we are removing key 3 now −m.remove(3)The following ... Read More

Create a TreeMap in Java and add key-value pairs

karthikeya Boyini
Published on 30-Jan-2019 12:38:55
A TreeMap cannot contain duplicate keys. TreeMap cannot contain the null key. However, It can have null values.Let us first see how to create a TreeMap −TreeMap<Integer, String> m = new TreeMap<Integer, String>();Add some elements in the form of key-value pairs −m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, ... Read More

Remove a value from TreeMap in Java

Samual Sam
Published on 30-Jan-2019 12:35:39
Use the remove() method to remove a value from TreeMap.Create a TreeMap first and add some elements −TreeMap<Integer, String> m = new TreeMap<Integer, String>(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Now, let’s say you need to remove a value with key 5. For ... Read More

How to Counting Chars in EditText Changed Listener in Android?

Chandu yadav
Published on 30-Jan-2019 12:29:28
Some situations, we have to restrict an edit text for some characters. To solve this situation, in this example demonstrate how to Counting Chars in Edit Text Changed Listener.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Retrieve TreeMap size in Java

karthikeya Boyini
Published on 30-Jan-2019 12:32:00
Get the TreeMap size using the size() method.First, create a TreeMap and add elements to it −TreeMap<Integer, String> m = new TreeMap<Integer, String>(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Count the number of elements in the above TreeMap or get the size using ... Read More

Java Program to get highest key stored in TreeMap

Samual Sam
Published on 30-Jan-2019 12:30:09
Use the lastKey() method to get the highest key stored in TreeMap.Let us first set the TreeMap and add some elements to it −TreeMap<Integer, String> m = new TreeMap<Integer, String>(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Now get the highest key −m.lastKey()The following ... Read More

Retrieve the last element from a LinkedList in Java

karthikeya Boyini
Published on 30-Jan-2019 12:27:51
The last element of a Linked List can be retrieved using the method java.util.LinkedList.getLast() respectively. This method does not require any parameters and it returns the last element of the LinkedList.A program that demonstrates this is given as follows −Example Live Demoimport java.util.LinkedList; public class Demo {    public static void ... Read More

Delete first and last element from a LinkedList in Java

Samual Sam
Published on 30-Jan-2019 12:25:52
The first element can be deleted from a LinkedList by using the method java.util.LinkedList.removeFirst(). This method does not have any parameters and it returns the first element of the LinkedList.The last element can be deleted from a LinkedList by using the method java.util.LinkedList.removeLast(). This method does not have any parameters ... Read More
Advertisements