zoukankan      html  css  js  c++  java
  • java常用技巧

    字符串转换成数值的方法
    String s="123";
    int i;
    第一种方法:i=Integer.parseInt(s);
    第二种方法:i=Integer.valueOf(s).intValue(); 转int整数


    String ss = "3.141592653"; 转double型
    double value = Double.valueOf(ss.toString());

    char和int之间的转换

    首先将char转换成string

    String str=String.valueOf('2')

    Integer.valueof(str) 或者Integer.PaseInt(str)

    Integer.valueof返回的是Integer对象,Integer.paseInt返回的是int

    string 和int之间的转换

    string转换成int :Integer.valueOf("12")

    int转换成string : String.valueOf(12)

    定位字符    

    int IndexOf(char value)

    int IndexOf(char value, int startIndex)

    int IndexOf(char value, int startIndex, int count)

    定位子串

    int IndexOf(string value) 

    int IndexOf(string value, int startIndex)

    nt IndexOf(string value, int startIndex)

    例:

    String s1="abcdefg";

    System.out.println(s1.indexOf("d"));//3

    System.out.println(s1.indexOf("e"));//4

    System.out.println(s1.indexOf("r"));//-1

    System.out.println(s1.indexOf("a",3));//-1从前往后,第三位开始定位a第一次出现的位置

    System.out.println(s1.indexOf("e",4,3));//4 从前往后,从第第四位开始查,查三位定义e

    lastIndexOf 方法

    查找字串中指定字符或字串最后出现的位置,返回索引值

  • 相关阅读:
    【MySQL】DBA必备的10款最佳MySQL GUI工具
    【MySQL】获取MySQL崩溃时的core file
    字符串经常用的
    centos 系统上如何把python升级为3
    centos6 升级安装openssh7
    多进程
    队列
    线程池,锁,事件
    thread
    进程、线程
  • 原文地址:https://www.cnblogs.com/ls-pankong/p/9321809.html
Copyright © 2011-2022 走看看