/* Program for basic String usage */ public class strings { public static void main(String[] args) { String s = "my string"; String word = "something"; System.out.println(s + '\n' + word + '\n' + s); char c; int i; c = s.charAt(0); // m // c = s.charAt(10); // runtime error // c = s.charAt(9); // error c = s.charAt(8); System.out.println("length of s is " + s.length()); // 9 i = word.indexOf('s'); // 0 i = word.indexOf('J'); // -1 because not there i = s.indexOf(' '); // find space, index 2 System.out.println(s.substring(i+1)); // from 3 to end s = s.substring(0,i); // "my" because second index not included System.out.println(s); if (s.equals("java")) System.out.println("s is java"); if (s.equalsIgnoreCase("My")) System.out.println("s is my"); } }