Found 33676 Articles for Programming

How to sort an ArrayList in Java in ascending order?

Priya Pallavi
Updated on 30-Jul-2019 22:30:21

681 Views

You can sort an ArrayList using the sort() method of the Collections class this method accepts a list object as a parameter and sorts the contents of it in ascending order.Example:import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class ArrayListSample {    public static void main(String[] args) {       ArrayList list = new ArrayList();       list.add("JavaFx");       list.add("Java");       list.add("WebGL");       list.add("OpenCV");       Set set = new LinkedHashSet(list);       Collections.sort(list);       System.out.println(list);    } }Output:[Java, JavaFx, OpenCV, WebGL]

How to synchronize an ArrayList in Java?

Nikitha N
Updated on 30-Jul-2019 22:30:21

266 Views

The synchronizedList(List list) method of the Collections class accepts a List object and returns a synchronized list backed by the specified list.Example:import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class ArrayListSample {    public static void main(String[] args){       ArrayList list = new ArrayList();       list.add("JavaFx");       list.add("Java");       list.add("WebGL");       list.add("OpenCV");       Set set = new LinkedHashSet(list);       Collections.synchronizedList(list);       System.out.println(list);    } }Output:[JavaFx, Java, WebGL, OpenCV]

How to match any non-digit character in Python using Regular Expression?

Pranav Indukuri
Updated on 23-Apr-2025 15:55:15

6K+ Views

A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions. In this article, we learn how to extract non-digit characters in Python using regular expressions. We use \D+ regular expression in Python to get non-digit characters from a string. Where, \D returns a match that does not contain digits. + implies zero or more occurrences of characters. ... Read More

How to reverse an ArrayList in Java?

Srinivas Gorla
Updated on 30-Jul-2019 22:30:21

459 Views

The Collections class provides a method named reverse() this method accepts a list and reverses the order of elements in it.Example:import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class Sample {    public static void main(String[] args){       ArrayList list = new ArrayList();       list.add("JavaFx");       list.add("Java");       list.add("WebGL");       list.add("OpenCV");       Set set = new LinkedHashSet(list);       System.out.println(set);       Collections.reverse(list);       System.out.println(list);    } }Output:[JavaFx, Java, WebGL, OpenCV] [OpenCV, WebGL, Java, JavaFx]

How to match any one uppercase character in python using Regular Expression?

Nikitasha Shrivastava
Updated on 23-Apr-2025 14:49:17

2K+ Views

There are two ways to match any one uppercase character in python using Regular Expression. One is the general method and other is using the regular expression. A regular expression is a series of characters that allows you to discover a string or a set of strings using a search pattern. Regular expressions are sometimes known as RegEx. In Python, the re module is used to work with regular expressions. How to Match an Uppercase Character? In this article we will match the uppercase vowel in Python using a regular expression. To do this we will use r'[A, E, I, ... Read More

How to match any one lowercase vowel in python using Regular Expression?

Nikitasha Shrivastava
Updated on 24-Apr-2025 11:35:43

1K+ Views

In this article, you will learn how to match any single lowercase vowel (a, e, i, o, u) using Python regular expressions (regex). We will understand how to use Python's re module to apply a pattern that finds these vowels in a string. Ways to Match Lowercase There are two ways to match any one lowercase vowel in Python using a Regular Expression. One is using the if loop, and the other is using a regular expression. Using the General Method ... Read More

What does the method removeLast() do in java?

Abhinaya
Updated on 30-Jul-2019 22:30:21

94 Views

The removeLast() method of the java.util.LinkedList class removes and returns the last element of this list.Example:import java.util.*; public class LinkedListDemo {    public static void main(String[] args) {       LinkedList list = new LinkedList();       list.add("Hello");       list.add(2);       list.add("Chocolate");       list.add("10");       System.out.println("LinkedList:" + list);       System.out.println("Last element:" + list.removeLast());       System.out.println("LinkedList:" + list);    } }Output:LinkedList:[Hello, 2, Chocolate, 10] Last element:10 LinkedList:[Hello, 2, Chocolate]

What does the method removeFirst() do in java?

Govinda Sai
Updated on 30-Jul-2019 22:30:21

138 Views

The removeFirst() method of the java.util.LinkedList class removes and returns the first element from this list.Example:import java.util.*; public class LinkedListDemo {    public static void main(String[] args) {       LinkedList list = new LinkedList();       list.add("Hello");       list.add(2);       list.add("Chocolate");       list.add("10");       System.out.println("LinkedList:" + list);       System.out.println("First element:" + list.removeFirst());       System.out.println("LinkedList:" + list);    } }Output:LinkedList:[Hello, 2, Chocolate, 10] First element:Hello LinkedList:[2, Chocolate, 10]

What does the method getLast() do in java?

Ramu Prasad
Updated on 30-Jul-2019 22:30:21

130 Views

The getLast() method of the class java.util.LinkedList returns the last element in this list.Example:import java.util.*; public class LinkedListDemo {    public static void main(String[] args) {       LinkedList list = new LinkedList();       list.add("Hello");       list.add(2);       list.add("Chocolate");       list.add("10");       System.out.println("LinkedList:" + list);       System.out.println("Last Element :" + list.getLast());    } }Output:LinkedList:[Hello, 2, Chocolate, 10] Last Element :10

What does the method getFirst() do in java?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

169 Views

The getFirst() method of the class java.util.LinkedList returns the first element of the current list. Example Live Demo import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); System.out.println("First Element :" + list.getFirst()); } } Output LinkedList:[Hello, 2, Chocolate, 10] First Element :Hello

Advertisements