Example - Using Strings

public class StrTest {

    public static void main(String[] args) {
        String course = "Intro to CS";
        String sub = course.substring(3,8);
        System.out.println(sub);
        sub = sub.toUpperCase();
        System.out.println(sub);
        int len = course.length();
        System.out.println("Length of course is " + len);
        System.out.println(course);
        int i = course.indexOf('C');
        StringBuffer update = new StringBuffer("Intro to CS");
        update.insert(5,"duction");
        System.out.println(update);
        StringBuffer next = new StringBuffer("Programming in C++");
        System.out.println(i);
        next.setCharAt(0,'X');
        next.setCharAt(15,'J');
        next.setCharAt(16,'a');
        next.setCharAt(17,'v');
        next.append("a Section 64");
        System.out.println(next);
    }
}

OUTPUT

C:\cafe1.8\Mine\StrTest>java StrTest
ro to
RO TO
Length of course is 11
Intro to CS
Introduction to CS
9
Xrogramming in Java Section 64


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page