Posts

Showing posts from June, 2023

Strings

  package JavaPra ; public class StingEx { public static void main (String[] args) { String name = "Myra Nirvana" ; System. out .println(name) ; // length of the string System. out .println(name.length()) ; //12 //Concatenate the String String s1 = "Welcome" ; String s2= "to my world" ; //join 2 strings System. out .println(s1+s2) ; System. out .println(s1.concat(s2)) ; String s3= "Automation" ; System. out .println(s1.concat(s2).concat(s3)) ; String s4= " SDET " ; // trim the left and right values System. out .println( "before Trim" +s4) ; s4.trim() ; System. out .println(s4.length()) ; System. out .println( "after Trim" ) ; System. out .println(s4.trim().length()+s4.trim()) ; System. out .println(name.charAt( 7 )) ; for ( int i = 0 ; i < name...

Java programs-Array

 Sort an Array using inbuilt Methods: package JavaPra ; import java.lang.reflect.Array ; import java.util.Arrays ; import java.util.Collections ; public class SortingArray { public static void main (String[] args) { int years[]= { 1988 , 2021 , 1991 , 2025 } ; //approach 1 Arrays. parallelSort (years) ; System. out .println(Arrays. toString (years)) ; int yearsolderst[]= { 1988 , 2021 , 1991 , 2025 } ; System. out .println( "Before Sorting---" +Arrays. toString (yearsolderst)) ; //approach 2--Ascending order Arrays. sort (yearsolderst) ; System. out .println( "After Sorting---" +Arrays. toString (yearsolderst)) ; ////approach 3- decending order Integer Tdates[]= { 1988 , 2021 , 1991 , 2025 } ; Arrays. sort (Tdates , Collections. reverseOrder ()) ; System. out .println(Arrays. toString (Tdates)) ; } } Output [1988, 1991, 2021, 2025] Before Sorting---[1988, ...