Java StringBuffer search substring

Introduction

The following program demonstrates indexOf() and lastIndexOf():


public class Main {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("one two one");
    int i;/*  www  . java 2  s .c  o m*/

    i = sb.indexOf("one");
    System.out.println("First index: " + i);

    i = sb.lastIndexOf("one");
    System.out.println("Last index: " + i);
  }
}



PreviousNext

Related