Posts

Learn Java Programming

Image
Lists of Java Topics and Programs for Selenium ➜ #1 OOPS: ----- Classes, Objects and Methods 1) OOPS concepts in Java with Examples ----- Overloading 1) Method Overloading Case 1 2) Method Overloading Case 2 3) Method Overloading Case 3 ----- Overriding ➜ #2 STRINGS: 1) Reverse a string in java using for loop 2) Reverse a string in java using for StringBuffer 3) Remove special characters from a String

Strings 03 - Write a program to remove special characters from a string

Image
Strings in Java - Program 03 ➜ Program 03: Write a program to remove special characters from a string. public class Test { public static void main(String[] args) { // Remove special characters String str = "!@@#Hello @#%#$^#%^#% World123007^&*()"; System.out.println(str); System.out.println(str.replaceAll("[^a-zA-Z0-9]", "")); } } --------Output-------- !@@#Hello @#%#$^#%^#% World123007^&*() HelloWorld123007 -----------------------

Strings 02 - Write a program to reverse a string in java using StringBuffer

Image
Strings in Java - Program 02 ➜ Program 02: Write a program to reverse a string in java using StringBuffer public class Test { public static void main(String[] args) { String s = "Hello"; System.out.println("Original String: " + s); StringBuilder sb = new StringBuilder(s); sb.reverse(); System.out.println("Reverse String: " + sb); } } --------Output-------- Original String: Hello Reverse String: olleH -----------------------

Strings 01 - Write a program to reverse a string in java using for loop

Image
Strings in Java - Program 01 ➜ Program 01: Write a program to reverse a string in java using for loop public class Test { public static void main(String[] args) { String str1 = "Hello"; System.out.println("Original String: " + str1); int size = str1.length(); String rev = ""; for (int i = size - 1; i >= 0; i--) { rev = rev + str1.charAt(i); } System.out.println("Reverse String: " + rev); } } --------Output-------- Original String: Hello Reverse String: olleH -----------------------

Arrays Programming Examples in Java - Part 2

Image
List of Java Array Programs - Part 2 ----------------------------------- 8. Find the Size of an Array. 9. Find Even and Odd in Array. 10. Find PRIME number in Array. 11. Increase each Array elements size by 1 . 12. Check Array contains the specific value. 13. Create Array List from Array . 14. Find Duplicate Using Brute Force Method. 15. Find Duplicate Using HashSet. 16. Remove Duplicates in Array using Set (HashSet). ----------------------------------- public class ArrayProgramsPart2 {  public static void main(String[] args) {   int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };   String[] s = { "Java", "C", "Java", "C", "NODDY", "SELENIUM", "AUTOTECHX" };   SizeOfArray(a);   EvenOdd(a);   PrimeNumber(a);   IncreaseArrayBy1(a);   ArrayContains(s);   CreateArrayListFromArray(s);   FindDuplicateUsingBruteForceMethod(s);   FindDuplicateUsingHashSet(s);   RemoveDuplic

Arrays in Java

Image
What are Java Array? Array is an Indexed Collection of Fixed Number of Homogeneous/Similar Data Elements . int[ ] x = new int[5]; Example: Valid   Array Examples: int[ ] arr1=new int[5]; int arr2[ ]=new int[5]; int [ ]arr3=new int[5]; int[ ] arr4 = new int[ ]{10,20,30,40,50}; int[ ] arr5 = {10,20,30,40,50}; Arrays can be initialized when they are declared. The array will automatically be created large enough to hold the number of elements you specify in the array initializer. There is  no  need to use  new . public static void main(String args[]) {    int month_days[ ];     month_days = new int[12];     month_days[0] = 31;     month_days[1] = 28;     month_days[2] = 31;     month_days[3] = 30;     month_days[4] = 31;     month_days[5] = 30;     month_days[6] = 31;     month_days[8] = 30;     month_days[9] = 31;     month_days[10] = 30;     month_days[11] = 31;      System.out.println(&quo