Java for Beginners, Lesson 24: String Methods and StringBuilder in Java
Lesson 23 showed what a String is. This lesson shows what you can do with one: search it, cut it, change its case, split it into words. Because Strings never change,…
Lesson 23 showed what a String is. This lesson shows what you can do with one: search it, cut it, change its case, split it into words. Because Strings never change,…
Names, messages, passwords, addresses: most real data is text. Java stores text in the String class. A String is not a primitive type (Lesson 8). It is an object, and…
Marks of 3 students in 4 subjects, a chessboard, a seating chart, a matrix in mathematics: all of these are tables with rows and columns. A two-dimensional (2D) array…
To store the marks of 100 students you would not create 100 separate variables. An array stores many values of the same type under one name, in a fixed-size row, and…
Normally a loop runs until its condition fails. But sometimes you want to stop early (you found what you needed) or skip one pass (that value should be ignored). Java…
When you know how many times to repeat, the for loop is the neatest choice. It puts the start, the condition and the update on a single line, so you can see the whole…
Printing the numbers 1 to 5 needs five lines. Printing 1 to 1000 should not need a thousand. A loop repeats a block of code as long as a condition stays true. Java…
Suppose a number from 1 to 7 should print a day name. An else-if ladder works, but it repeats the same test again and again. A switch statement is a cleaner way to…
So far every program ran line after line, in order. Real programs need to choose: if the marks are 40 or more, print “Pass”; otherwise print “Fail”. Java makes…
You now know the arithmetic, comparison, logical and bitwise operators. This lesson covers three more things: the assignment operator, the ternary operator (a…