zoukankan      html  css  js  c++  java
  • StringDemo1

    package cn.zuoye;
    /*
     * string 类的获取功能
     * int length()获取字符串长度
     * char charAt(int index)获取指定索引位置的字符
     * 这里用int类型,因为97也等于a
     * int indexOf(int ch)返回指定 字符 在此字符串中第一次出现处的索引
     * int indexOf(string str)返回指定 字符串 在此字符串中第一次出现处的索引
     * int indexOf(int ch,int fromIndex)返回指定 字符 在此字符串中从指定位置后第一次出现处的索引
     * int indexOf(string str,int fromIndex)返回指定 字符串 在此字符串中从指定位置后第一次出现处的索引
     * string substring(int start) 从指定位置开始截取字符串,默认到结尾
     * string substring(int start,int end)从指定位置开始到指定位置结束 截取字符串
     */
    public class StringDemo1 {
     public static void main(String[] args) {
      //定义一个字符串对象
      String s = "helloworld";
      //int length()获取字符串长度
      System.out.println("s.length:"+s.length());
     
      //char charAt(int index)获取指定索引位置的字符
      System.out.println("charAt:"+s.charAt(5));
      
      //int indexOf(int ch)返回指定 字符 在此字符串中第一次出现处的索引
      System.out.println("indexOf:"+s.indexOf('l'));
      
      //int indexOf(string str)
      System.out.println("indexOf:"+s.indexOf("lo"));
      
      //int indexOf(int ch,int fromIndex)
      System.out.println("indexOf:"+s.indexOf('l',2));
      
      //string substring(int start)
      System.out.println("subString:"+s.substring(5));
      
      //string substring(int start,int end)
      System.out.println("substring:"+s.substring(3,9));//[3,9)
     }
    }

  • 相关阅读:
    LeetCode 230. Kth Smallest Element in a BST
    LeetCode 114. Flatten Binary Tree to Linked List
    LeetCode 222. Count Complete Tree Nodes
    LeetCode 129. Sum Root to Leaf Numbers
    LeetCode 113. Path Sum II
    LeetCode 257. Binary Tree Paths
    Java Convert String & Int
    Java Annotations
    LeetCode 236. Lowest Common Ancestor of a Binary Tree
    LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
  • 原文地址:https://www.cnblogs.com/rong123/p/9894437.html
Copyright © 2011-2022 走看看