123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Detail Description About Java Array And Regex

Profile Picture
By Author: INFOCAMPUS is Best JAVA Training Center In Bangalo
Total Articles: 40
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Normally, array is a collection of similar type of elements that have contiguous memory location.
Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array.

Array in java is index based, first element of the array is stored at 0 index.
Advantage of Java Array
• Code Optimization: It makes the code optimized, we can retrieve or sort the data easily.
• Random access: We can get any data located at any index position.

Disadvantage of Java Array
Size Limit: We can store only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in java. Best core java training in Bangalore

Types of Array in java
There are two types of array.
• Single Dimensional Array
• Multidimensional Array


Single Dimensional Array
One dimensional array is a list of variables of same type that are accessed by a common name. An individual variable in the array is called ...
... an array element. Arrays forms a way to handle groups of related data.

Multidimensional Array
In Java, multidimensional arrays are actually arrays of arrays. These, as you might expect, look and act like regular multidimensional arrays. However, as you will see, there are a couple of subtle differences. To declare a multidimensional array variable, specify each additional index using another set of square brackets. For example, the following declares a two-dimensional array variable called twoD.

When you allocate memory for a multidimensional array, you need only specify the memory for the first (leftmost) dimension. You can allocate the remaining dimensions separately.
While there is no advantage to individually allocating the second dimension arrays in this situation, there may be in others. For example, when you allocate dimensions manually, you do not need to allocate the same number of elements for each dimension. As stated earlier, since multidimensional arrays are actually arrays of arrays, the length of each array is under your control. For example, the following program creates a two-dimensional array in which the sizes of the second dimension are unequal. best java training institute bangalore Marathahalli


Java Regex
The Java Regex or Regular Expression is an API to define pattern for searching or manipulating strings.
It is widely used to define constraint on strings such as password and email validation. After learning java regex tutorial, you will be able to test your own regular expressions by the Java Regex Tester Tool.
Java Regex API provides 1 interface and 3 classes in java.util.regex package.
java.util.regex package
It provides following classes and interface for regular expressions. The Matcher and Pattern classes are widely used in java regular expression.
1. MatchResult interface
2. Matcher class
3. Pattern class
4. PatternSyntaxException class

Matcher class
It implements MatchResult interface. It is a regex engine i.e. used to perform match operations on a character sequence.
No. Method Description
1 boolean matches() test whether the regular expression matches the pattern.
2 boolean find() finds the next expression that matches the pattern.
3 boolean find(int start) finds the next expression that matches the pattern from the given start number.
4 String group() returns the matched subsequence.
5 int start() returns the starting index of the matched subsequence.
6 int end() returns the ending index of the matched subsequence.
7 int groupCount() returns the total number of the matched subsequence.
Pattern class
It is the compiled version of a regular expression. It is used to define a pattern for the regex engine.
No. Method Description
1 static Pattern compile(String regex) compiles the given regex and return the instance of pattern.
2 Matcher matcher(CharSequence input) creates a matcher that matches the given input with pattern.
3 static boolean matches(String regex, CharSequence input) It works as the combination of compile and matcher methods. It compiles the regular expression and matches the given input with the pattern.
4 String[] split(CharSequence input) splits the given input string around matches of given pattern.
5 String pattern() returns the regex pattern.
Regex Character classes
No. Character Class Description
1 [abc] a, b, or c (simple class)
2 [^abc] Any character except a, b, or c (negation)
3 [a-zA-Z] a through z or A through Z, inclusive (range)
4 [a-d[m-p]] a through d, or m through p: [a-dm-p] (union)
5 [a-z&&[def]] d, e, or f (intersection)
6 [a-z&&[^bc]] a through z, except for b and c: [ad-z] (subtraction)
7 [a-z&&[^m-p]] a through z, and not m through p: [a-lq-z](subtraction)
Regex Metacharacters
The regular expression metacharacters work as a short codes.
Regex Description
. Any character (may or may not match terminator)
\d Any digits, short of [0-9]
\D Any non-digit, short for [^0-9]
\s Any whitespace character, short for [\t\n\x0B\f\r]
\S Any non-whitespace character, short for [^\s]
\w Any word character, short for [a-zA-Z_0-9]
\W Any non-word character, short for [^\w]
\b A word boundary
\B A non word boundary

More About the Author

We offer innovative and customized Java Training in Bangalore. Best Java course in Bangalore with Certified Experts. Go to free demo classes, get prepared by 8yrs experienced tutors and furthermore get hands on live project. Visit: http://infocampus.co.in/java-training-bangalore.html

Total Views: 564Word Count: 732See All articles From Author

Add Comment

Computer Programming Articles

1. Which Are The Best Java Coding Classes In Bhopal?
Author: Shankar Singh

2. Warehouse Management In Zambia: Essential Features To Look For
Author: Doris Rose

3. Ecommerce Web Design And Development In Melbourne With The Merchant Buddy
Author: themerchantbuddy

4. Why Website Maintenance Is Crucial For Business Success
Author: Yogendra Shinde

5. Boost Your Business With Smart Invoice Pos Software In Zambia
Author: Cecilia Robert

6. How Stablecoin Development Ensures Stability And Security?
Author: Michael noah

7. Công Cụ Tính Chiều Cao Chuẩn Từ Minbin Tool: Đo Lường Và Cải Thiện Chiều Cao Hiệu Quả
Author: KenJi123

8. How To Make A Courier App For Courier Delivery And Tracking Service
Author: Deorwine Infotech

9. Reputation Management In The Digital Age: Protecting And Enhancing Your Law Firm’s Image
Author: jamewilliams

10. What Features Should I Look For In Wordpress Ecommerce Plugins?
Author: Rocket Press

11. Staying Updated With The Latest Gaming News
Author: Next Tech Plus

12. Game Development: Evolving Technologies And New Horizons
Author: Rick John

13. Why Svelte Is The Most In-demand Framework For Web Development?
Author: Why Svelte Is The Most In-Demand Framework For Web

14. Maximizing Ebay Sales With Maropost/neto And Pursuit Info Solutions
Author: rachelvander

15. The Importance Of Software Testing: Ensuring Quality In Development
Author: John Mathew

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: