java基础语法-string类

String num1

## 获取字符串长度

num1.length()

## 获取索引 i 处的字符char

public class Test {
    
    
    public static void main(String args[]) {
    
    
        String s = "www.runoob.com";
        char result = s.charAt(6);
        System.out.println(result);
    }
}

输出为: n

## 提取部分字符串

public class Solution {
    
    
	public String reverseLeftWords(String s, int n){
    
    
		return s.substring(n,s.length()) + s.substring(0,n);
	}

}

猜你喜欢

转载自blog.csdn.net/xiaonuanhu/article/details/108013651
今日推荐