1 /* 2 * Program to illustrate some basic character string processing functionality 3 */ 4 5 package stringthing; 6 7 public class StringOps { 8 9 public static void main(String[] args) { 10 11 // ESTABLISH SOME STRINGS 12 String date = "Wednesday, March 9, 2022"; 13 String time = "12 PM"; 14 String lab = "String Thing"; 15 16 // COMPUTE THE LENGTHS OF THE STRINGS 17 int dateLength = date.length(); 18 int timeLength = time.length(); 19 int labLength = lab.length(); 20 System.out.println("\ndateLength = " + dateLength); 21 System.out.println("timeLength = " + timeLength); 22 System.out.println("labLength = " + labLength); 23 24 // COMPUTE SOME POSITIONS 25 int p1 = date.indexOf(","); 26 int p2 = time.indexOf(","); 27 int p3 = lab.indexOf("ing"); 28 System.out.println("\np1 = " + p1); 29 System.out.println("p2 = " + p2); 30 System.out.println("p3 = " + p3); 31 32 // COMPUTE SOME 2 ARGUEMENT SUBSTRING VALUES 33 System.out.println("\ndate.substring(0,9) = " + date.substring(0,9)); 34 System.out.println("time.substring(2,4) = " + time.substring(2,4)); 35 System.out.println("lab.substring(7,8) = " + lab.substring(7,8)); 36 37 // COMPUTE SOME 1 ARGUEMENT SUBSTRING VALUES 38 System.out.println("\ndate.substring(11) = " + date.substring(11)); 39 System.out.println("time.substring(2) = " + time.substring(2)); 40 System.out.println("lab.substring(7) = " + lab.substring(7)); 41 42 // CREATE A STRING 43 String line = date + " | " + time + " | " + lab; 44 System.out.println("\nline = " + line); 45 } 46 } 47