There are multiple ways to loop over an array in Java e.g. you can use a for loop, an enhanced for loop, a while loop or a do-while loop. Since while and do-while needs a condition to terminate they often depend upon the content of the array e.g. stop when the current element is null or even or odd etc. If you just want to iterate over an array to access each element e.g. loop over an array and print each entry then you should use either for loop or the enhanced for loop. The traditional for loop uses a counter and allows you to iterate until the last element is reached i.e. counter is equal to the length of the array while enhanced for loop maintains that counter internally, allowing you to iterate without worrying about counts. This results in clean code and it also eliminates the possibility of one-off errors. In this article, I'll show you 2 ways to iterate over an array, first by using traditional for loop and second by using enhanced for loop of Java 1.5.
Declaring a two-dimensional array is interesting in Java as Java programming language provides many ways to declare a 2D array and each way have some special things to learn about. For example, It's possible to create a two-dimensional array in Java without specifying the second dimension, sounds crazy right? but it's possible because two-dimensional array in Java is nothing but an array of array. You can even create a two-dimensional array where each subarray has different length or different type, also known as a heterogeneous array in Java. Some of the ways described here also apply how you to declare one-dimensional array e.g. changing the place of square brackets and it has implication on any other variables declared in the same line.
You can use regular expression and replaceAll() method of java.lang.String class to remove all special characters from String. A special character is nothing but characters like ! #, % etc. Precisely, you need to define what is a special character for you. Once you define that you can use a regular expression to replace those character with empty String, which is equivalent to removing all special characters from String. For example, suppose, your String contains some special characters e.g. "Awesome!!!" and you want to remove those !!! to reduce some excitement, you can use replaceAll("!", "") to get rid of all exclamation mark from String. Similarly, if you String contains many special characters, you can remove all of them by just picking alphanumeric characters e.g. replaceAll("[^a-zA-Z0-9_-]", ""), which will replace anything with empty String except a to z, A to Z, 0 to 9,_ and dash. Let's see couple fo examples to remove all special characters from String in Java.