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