zoukankan      html  css  js  c++  java
  • java期末复习2

    java string

    String s;
    s=s.concat("AA");//将“AA”连接到s之后
    
    s=String.valueOf(123);//将括号内的值转化为字符串存在s中
    
    s.indexOf('o')//在s中寻找‘o’首次出现的位置
    
    s.lastIndexOf('o')//在s中寻找‘o’最后一次出现的位置
    
    s.indexOf('o',5)//在s中从第五个字符开始寻找‘o’首次出现的位置
    
    s.lastIndexOf('o')//在s中从倒数第五个字符开始从右至左寻找‘o’一次出现的位置
    
    

    StringBuffer 类

    public class Test{
      public static void main(String args[]){
        StringBuffer sBuffer = new StringBuffer("AA");
        sBuffer.append("12"); 
        System.out.println(sBuffer);  
      }
    }
    //outresult is "AA12"
    
    
    StringBuffer 类特有方法
    1 public StringBuffer append(String s) 将指定的字符串追加到此字符序列。
    2 public StringBuffer reverse() 将此字符序列用其反转形式取代。
    3 public delete(int start, int end) 移除此序列的子字符串中的字符。
    4 public insert(int offset, int i) 将 int 参数的字符串表示形式插入此序列中。
    5 replace(int start, int end, String str) 使用给定 String 中的字符替换此序列的子字符串中的字符。
    和string相同的方法
    1 int capacity() 返回当前容量。
    2 char charAt(int index) 返回此序列中指定索引处的 char 值。
    3 void ensureCapacity(int minimumCapacity) 确保容量至少等于指定的最小值。
    4 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 将字符从此序列复制到目标字符数组 dst
    5 int indexOf(String str) 返回第一次出现的指定子字符串在该字符串中的索引。
    6 int indexOf(String str, int fromIndex) 从指定的索引处开始,返回第一次出现的指定子字符串在该字符串中的索引。
    7 int lastIndexOf(String str) 返回最右边出现的指定子字符串在此字符串中的索引。
    8 int lastIndexOf(String str, int fromIndex) 返回 String 中子字符串最后出现的位置。
    9 int length() 返回长度(字符数)。
    10 void setCharAt(int index, char ch) 将给定索引处的字符设置为 ch
    11 void setLength(int newLength) 设置字符序列的长度。
    12 CharSequence subSequence(int start, int end) 返回一个新的字符序列,该字符序列是此序列的子序列。
    13 String substring(int start) 返回一个新的 String,它包含此字符序列当前所包含的字符子序列。
    14 String substring(int start, int end) 返回一个新的 String,它包含此序列当前所包含的字符子序列。
    15 String toString() 返回此序列中数据的字符串表示形式。

    输入类:

    import java.util.Scanner;
    public static void main(String [] args) { 
             Scanner sc = new Scanner(System.in); 
              
             String name = sc.nextLine(); 
              
             int age = sc.nextInt(); 
               
             float salary = sc.nextFloat(); 
             
             System.out.println("姓名:"+name+"
    "+"年龄:"+age+"
    "+"工资:"+salary); 
    }
    
    //代标号的break和带标号的continue,跳转到标号处
    
    instanceof//作用等同==
    
  • 相关阅读:
    Java并发组件三之Semaphore
    Java并发组件二之CyclicBarriar
    Java并发组件一之CountDownLatch
    高并发多线程二
    多线程与高并发需要体会记住的点
    Maven 知识点总结以及解决jar报冲突的几种方法
    JAVA SSM整合流程以及注意点
    SpringMVC Tomcat 启动时报错:java.lang.IllegalStateException: Error starting child
    java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
    javax.servlet.ServletException: No adapter for handler
  • 原文地址:https://www.cnblogs.com/dpsama/p/12031222.html
Copyright © 2011-2022 走看看