Remove Element from ArrayList Using ListIterator in Java

Chandu yadav
Updated on 29-Jun-2020 13:48:11

1K+ Views

An element can be removed from an ArrayList using the ListIterator method remove(). This method removes the current element in the ArrayList. If the remove() method is not preceded by the next() method, then the exception IllegalStateException is thrown.A program that demonstrates this is given as follows.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; public class Demo {    public static void main(String[] args) {       ArrayList aList = new ArrayList();       aList.add("Apple");       aList.add("Mango");       aList.add("Guava");       aList.add("Orange");       aList.add("Peach");       System.out.println("The ArrayList elements are: ");     ... Read More

Compare Strings in Android

Nishtha Thakur
Updated on 29-Jun-2020 13:48:03

2K+ Views

This example demonstrate about How to use compare string 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.                     In the above code, we have taken edittext, button and textviews. When user click on button, it will take the data from edittext and manipulate with string with string comparing techniques. The result of manipulation data append to textview’sStep 3 − Add the following code ... Read More

Get Thread Group Information in Android

Anvi Jain
Updated on 29-Jun-2020 13:47:36

295 Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to get thread group information 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.     In the above code, we have taken textview. It contains information about current thread group information.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

Replace Element in ArrayList Using ListIterator in Java

George John
Updated on 29-Jun-2020 13:47:32

1K+ Views

An element in ArrayList can be replaced using the ListIterator method set(). This method has a single parameter i.e. the element that is to be replaced and the set() method replaces it with the last element returned by the next() or previous() methods.A program that demonstrates this is given as follows.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; public class Demo {    public static void main(String[] args) {       ArrayList aList = new ArrayList();       aList.add("Amanda");       aList.add("Taylor");       aList.add("Justin");       aList.add("Emma");       aList.add("Peter");       System.out.println("The ArrayList elements ... Read More

Get All Stack Traces of Current Thread in Android

Nishtha Thakur
Updated on 29-Jun-2020 13:47:07

294 Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to get getAllStackTraces of current thread 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.     In the above code, we have taken textview. It contains information about current thread stack trace.Step 3 − Add the following code to src/MainActivity.javapackage ... Read More

Iterate Through Elements of a LinkedList Using ListIterator in Java

Ankith Reddy
Updated on 29-Jun-2020 13:46:41

251 Views

A ListIterator can be used to traverse the elements in the forward direction as well as the reverse direction in a LinkedList.The method hasNext( ) in ListIterator returns true if there are more elements in the LinkedList while traversing in the forward direction and false otherwise. The method next( ) returns the next element in the LinkedList and advances the cursor position.The method hasPrevious( ) in ListIterator returns true if there are more elements in the LinkedList while traversing in the reverse direction and false otherwise. The method previous( ) returns the previous element in the LinkedList and reduces the ... Read More

Get Current Thread State in Android

Anvi Jain
Updated on 29-Jun-2020 13:46:20

287 Views

Before getting into example, we should know what thread is. A thread is a lightweight sub-process, it going to do back ground operations without interrupt to ui. This example demonstrate about How to get current thread 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.     In the above code, we have taken textview. It contains information about the current thread state.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

Get Current Thread Priority in Android

Nishtha Thakur
Updated on 29-Jun-2020 13:45:50

569 Views

Before getting into example, we should know what thread is. A thread is a lightweight sub-process, it going to do back ground operations without interrupt to ui. This example demonstrate about How to get current thread priority 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.     In the above code, we have taken textview. It contains information about current thread priority.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

Declare Abstract Method in Java: Private, Protected, Public or Default

Maruthi Krishna
Updated on 29-Jun-2020 13:45:25

12K+ Views

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation to it.Declaring an abstract method privateIf a method of a class is private, you cannot access it outside the current class, not even from the child classes of it.But, incase of an abstract method, you cannot use it from the same class, you need to override it from subclass and use.Therefore, the abstract method cannot ... Read More

Create Object Array from Elements of LinkedList in Java

Chandu yadav
Updated on 29-Jun-2020 13:45:11

449 Views

An object array can be created from the elements of a LinkedList using the method java.util.LinkedList.toArray(). This method returns the object array with all the LinkedList elements in the correct order.A program that demonstrates this is given as follows.Example Live Demoimport java.util.LinkedList; public class Demo {    public static void main(String[] args) {       LinkedList l = new LinkedList();       l.add("Amy");       l.add("Sara");       l.add("Joe");       l.add("Betty");       l.add("Nathan");       Object[] objArr = l.toArray();       System.out.println("The object array elements are: ");       for ... Read More

Advertisements