How to get the length of a string using Apex in Salesforce?

Sample Code:

String str = 'biswajeet';
Integer i = str.length();
System.debug('size: ' + i)