- 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 9321 Articles for Object Oriented Programming
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
261 Views
ExampleLive Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class NoRegTest { public static void main(String[] args) { String s="^fun"; Pattern pattern = Pattern.compile(s); Matcher matcher = pattern.matcher("Java is fun"); if(!matcher.find()) { System.out.println("not found"); } } }Outputnot found
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
980 Views
regex ^((?!kk).)*$ returns true if a line does not contain kk, otherwise returns falseExamplepublic class RegTest { public static void main(String[] args) { // TODO Auto-generated method stub String s="tutorials"; boolean i=s.matches("^((?!kk).)*$"); System.out.println(i); } }
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
454 Views
Exampleimport java.util.regex.*; class PatternMatch{ public static void main(String args[]) { String content = "I am a student"; String string = ".*boy.*"; boolean isMatch = Pattern.matches(string, content); System.out.println("The line contains 'boy'?"+ isMatch); } }Outputthe line contains 'boy'?falsematches()It is used to check if the whole text matches a pattern. Its output is boolean. It returns true if match is found otherwise false.This is one of simplest and easiest way of searching a String in a text using Regex .There is a another method compile() , if you want ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
853 Views
In Java regex matches() matches the input string against the whole string as it add a ^ and $ at the end of the input string.so it will not match the substring. So for matching substring, you should use find().Exampleimport java.util.regex.*; class PatternMatchingExample { public static void main(String args[]) { String content = "aabbcc"; String string = "aa"; Pattern p = Pattern.compile(string); Matcher m = p.matcher(content); System.out.println(" 'aa' Match:"+ m.matches()); System.out.println(" 'aa' Match:"+ m.find()); } }Output'aa' Match:false 'aa' Match:true
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
594 Views
ExampleLive Demoimport java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SearchRegex { private Pattern subPattern = Pattern.compile(SUBJECT_PATTERN); private Matcher matcher; private static final String SUBJECT_PATTERN = "(?s)Subject 1:\s(.*)Subject 2:"; public static void main(String[] args) { String d = "Subject 1: Java" + "Subject 2: Python"; SearchRegex obj = new SearchRegex(); List list = obj.getSubject(d); System.out.println("Address Result : " + list); } private List getSubject(String d){ List result = new ArrayList(); matcher = subPattern.matcher(d); while (matcher.find()) { result.add(matcher.group(1)); } return result; } }OutputAddress Result : [Java]
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
221 Views
the syntax? i:x makes the string search case-insensitive. for egpublic class RegCaseSense { public static void main(String[] args) { String stringSearch = "HI we are at java class."; // this won't work because the pattern is in upper-case System.out.println("Try this 1: " + stringSearch.matches(".*CLASS.*")); // the magic (?i:X) syntax makes this search case-insensitive, so it returns true System.out.println("Try this 2: " + stringSearch.matches("(?i:.*CLASS.*)")); } }
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
731 Views
There are many sites which are a good resource for java interview questions-answers. Following is the list of most popular websites.Tutorialspointwww.Tutorialspoint.comStackOverflowwww.stackoverflow.comDZonewww.dzone.comWikipediawww.wikipedia.orgIBM Developer Workswww.ibm.com/developerworks/java/
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
181 Views
Widening refers to passing a lower size data type like int to a higher size data type like long. Method overloading is possible in such case. ExampleLive Demopublic class Tester { public static void main(String args[]) { Tester tester = new Tester(); short c = 1, d = 2; int e = 1, f = 2; System.out.println(tester.add(c, d)); System.out.println(tester.add(e, f)); } public int add(short a, short b) { System.out.println("short"); return a + b; } public int add(int a, int b) { System.out.println("int"); return a + b; } } OutputShort 3 Int 3
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
70 Views
There are three kinds of variables in Java −Local variablesInstance variablesClass/Static variablesLocal VariablesLocal variables are declared in methods, constructors, or blocks.Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block.Access modifiers cannot be used for local variables.Local variables are visible only within the declared method, constructor, or block.Local variables are implemented at stack level internally.There is no default value for local variables, so local variables should be declared and an initial value should be assigned before the first use.ExampleHere, age is a local variable. ... Read More