- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34487 Articles for Programming
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
279 Views
A class declaration can contain a single method. A program that demonstrates this is given as follows:Example Live Democlass Message { public void messagePrint() { System.out.println("This is a class with a single method"); } } public class Demo { public static void main(String args[]) { Message m = new Message(); m.messagePrint(); } }OutputThis is a class with a single methodNow let us understand the above program.The Message class is created with a single member function messagePrint(). A code snippet which demonstrates this is as follows −class Message { ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
185 Views
The Matcher.find(int) method finds the subsequence in an input sequence after the subsequence number that is specified as a parameter. This method is available in the Matcher class that is available in the java.util.regex package.The Matcher.find(int) method has one parameter i.e. the subsequence number after which the subsequence is obtained and it returns true is the required subsequence is obtained else it returns false.A program that demonstrates the method Matcher.find(int) in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
108 Views
An example of a read-only collection can be an unmodifiable ArrayList. The unmodifiable view of the specified ArrayList can be obtained by using the method java.util.Collections.unmodifiableList(). This method has a single parameter i.e. the ArrayList and it returns the unmodifiable view of that ArrayList.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) throws Exception { List aList = new ArrayList(); aList.add("Apple"); aList.add("Mango"); aList.add("Guava"); aList.add("Orange"); aList.add("Peach"); ... Read More
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
129 Views
Multiple characters can be treated as a single unit using groups in Java regular expressions. The method java.time.Matcher.group() is used to find the subsequence in the input sequence string that is a match to the required pattern.A program that demonstrates groups in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("\w\d"); Matcher m = p.matcher("I am f9"); System.out.println("The input string is: I am f9"); System.out.println("The Regex is: \w\d"); ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
13K+ Views
A thread can be created by implementing the Runnable interface and overriding the run() method.The current thread is the currently executing thread object in Java. The method currentThread() of the Thread class can be used to obtain the current thread. This method requires no parameters.A program that demonstrates this is given as follows −Example Live Demopublic class Demo extends Thread { public void run() { for (int i = 0; i < 5; i++) { System.out.println("The Thread name is " + Thread.currentThread().getName()); } } public static void main(String[] ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
91 Views
The method java.time.Matcher.matches() matches the given region against the specified pattern. It returns true if the region sequence matches the pattern of the Matcher and false otherwise.A program that demonstrates the method Matcher.matches() in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("Apple"); String str1 = "apple"; String str2 = "Apple"; String str3 = "APPLE"; Matcher m1 = p.matcher(str1); Matcher m2 = p.matcher(str2); ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
397 Views
The extreme elements in a list are the maximum and minimum elements. These can be obtained using the java.util.Collections.max() and java.util.Collections.min() methods respectively.The Collections.max() method contains a single parameter i.e. the list whose maximum element is to be found and it returns the maximum element from the list. The Collections.min() method contains a single parameter i.e. the list whose minimum element is to be found and it returns the minimum element from the list.A program that demonstrates this is given as follows:Exampleimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
8K+ Views
A list can be sorted in reverse order i.e. descending order using the java.util.Collections.sort() method. This method requires two parameters i.e. the list to be sorted and the Collections.reverseOrder() that reverses the order of an element collection using a Comparator.The ClassCastException is thrown by the Collections.sort() method if there are mutually incomparable elements in the list.A program that demonstrates this is given as follows:Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { List aList = new ArrayList(); ... Read More
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
94 Views
A list can be sorted in ascending order using the java.util.Collections.sort() method. This method requires a single parameter i.e. the list to be sorted and no value is returned. The ClassCastException is thrown by the Collections.sort() method if there are mutually incomparable elements in the list.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { List aList = new ArrayList(); aList.add("James"); aList.add("Harry"); aList.add("Susan"); aList.add("Emma"); aList.add("Peter"); ... Read More
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
225 Views
Binary Search can be performed in Java using the method java.util.Collections.binarySearch(). This method requires two parameters i.e. the list in which binary search is to be performed and the element that is to be searched. It returns the index of the element if it is in the list and returns -1 if it is not in the list.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) { List aList = new ArrayList(); aList.add("James"); aList.add("George"); ... Read More