StringBuffer str = new StringBuffer("Hello, World!") int index = str.indexOf("World"); System.out.println("Index of 'World': " + index);
StringBuffer str = new StringBuffer("Hello, World!") int index = str.indexOf("Java"); System.out.println("Index of 'Java': " + index);Output: Index of 'Java': -1 This method is part of the java.lang package library.