java interception

To a small Title: Prior to also put a

Digital 6.99999 get the first two, 6.9

 

 

 Code:

Package com.obge.contr;
 public  class Teststu {     
     public  static  void main (String [] args) {    
         double DU1 = 6.99999 ;
         // transformed by packaging, the double type to a String
         // Returns the object string It represents still essentially toString 
        String S1 = the Double.toString (DU1);
        String s2 =  String.valueOf(du1);
        S3 String = "" + DU1;        
         // indexof return position to develop character in a string for the first time, there is no return -1, note indexof is zero
         // substring note oh: on the left contains the right does not include also starting from 0, the direction from left to right are 
        String s2.substring SS = (0, s2.indexOf () + 2 "." );        
         // String type converted to double parse parse 
        DU1 = Double.parseDouble ( ss);
        
        System.out.println ( "decimal point position is located:" "." + S2.indexOf ( ));
        System.out.println ( "Double String converted into three types of way:" );
        System.out.println (S2 + "type is:" + getType (S2));
        System.out.println (S1 + "type is:" + getType (S1));
        System.out.println (S3 + "type is:" + getType (S3));
        
        System.out.println (SS + "type is:" + getType (SS));
        System.out.println ( "final value after conversion is:" + du1 + "type is:" + getType (DU1));
                    
        
    }
    // Get Variable Type Method 
    public  static String getType (Object O) { 
         // call the method returns variable type getClass () method 
        return o.getClass () toString ().;
        
        }     

}

 

1、subString

Two ways:

  substring(beginIndex)

       substring(beginIndex, endIndex)

Note: the time taken from scratch, comprising the left to the right is not included, were taken (endIndex-beginIndex + 1) character  , if the range is greater than the total number of strings to be taken will be given.

 

 

 

By editing software such as: eclipse can be seen SubString usage, but also gives an example, there can be seen two, you can pass a parameter or two parameters

 

 

 Simple small example

 

 

2、indexof()

public int indexOf (int ch): Returns the index of the first occurrence of the character in the string, if no such character string, returns -1.
public int indexOf (int ch, int fromIndex): return from the start position to find fromIndex index of the first occurrence of the specified character in the string, if no such character string, returns -1.
int indexOf (String str): Returns the index of the first occurrence of the character in the string, if no such character string, returns -1.
int indexOf (String str, int fromIndex): return from fromIndex position to start looking at the index specified character first appeared in a string, if no such character string, or -1.
  

Anyway, that is, there are strings corresponding to the position where the returns, but also from scratch, not just -1

Guess you like

Origin www.cnblogs.com/obge/p/12163099.html