Java的学习 11.24

Java学习 String类

1.1 API文档的使用

我们java是开源的,所以又很多类看不懂可以看底层代码。例如:
 @Test
    public void test1(){
​
        String  str = "asdfasdf";
        char a = str.charAt(6);
        System.out.println(a);
        
    }    
    
 此时我们charAt究竟作用是什么,参数代表什么意思 返回值代表什么意思我们无从得之,所以可以ctrl+左键查看代码   
​
/**
     * Returns the {@code char} value at the
     * specified index. An index ranges from {@code 0} to
     * {@code length() - 1}. The first {@code char} value of the sequence
     * is at index {@code 0}, the next at index {@code 1},
     * and so on, as for array indexing.
     *
     * <p>If the {@code char} value specified by the index is a
     * <a href="Character.html#unicode">surrogate</a>, the surrogate
     * value is returned.
     *
     * @param      index   the index of the {@code char} value.
     * @return     the {@code char} value at the specified index of this string.
     *             The first {@code char} value is at index {@code 0}.
     * @exception  IndexOutOfBoundsException  if the {@code index}
     *             argument is negative or not less than the length of this
     *             string.
     */
    public char charAt(int index) {
        if ((index < 0) || (index >= value.length)) {
            throw new StringIndexOutOfBoundsException(index);
        }
        return value[index];
    }
​
这个方法很慢,所以就有了API(Application Programming Interface,应用程序接口)文档,他有中文版 而且所有类都包含了,我们看起来就方便了
    
首先打开文档    
    
 我们发现其将java所有的类都罗列出来了
 java中的常用包:  lang java的语言核心包    io java的输入输出流  math 数学工具包
                 net  java的网络包       sql java中数据库操作相关的包   util java的工具包
    
    
  我们要使用得类是String  所以通过索引搜索String 
    
A 继承关系
public final class String
extends Object
implements Serializable, Comparable<String>, CharSequence
​
B String的简介
C 构造方法    
D 静态方法
E 接口方法
    
所以实现某个功能可以去百度    

1.2 String练习题

1  有一个字符串 "hello world" ,请获取其第三个子字符
2  有一个字符串 "hello world" ,请判断 lo首次出现的索引位置
3  有一个字符串 "  hello world   " ,请去处其空格
4  有一个字符串 "hello world" , 请将 world 换成 java
5  有一个字符串 "hello world" , 是否包含 ld ?
6  有一个字符串 "hello wo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值