Dark Horse programmer--15,string, basic data Type wrapper object

Source: Internet
Author: User

------<ahref= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------

Dark Horse programmer--15,string, basic data Type wrapper object

/* string-related exercises */* for the largest of two strings of the same substring, thinking: 1, the short substring in the form of decreasing length of the way to obtain 2, each gets to the substring of the long string to determine whether it contains */class zfclx{                   public static void Main (string[] args) {String a= "KJESQWERSJFNQWG";            String b= "CCAAQWERXYHS";            String c= Zichuan (b,a);                   String d= zichuan2 (b,a);         System.out.println ("c=" +c);                   public static string Zichuan (string s1,string s2) {if (S1.length () <s2.length ())                      {String s3= "";                      S3=S1;                      S1=S2;                   S2=S3;       } string Op= "";//Set a variable here to store the returned string string[][] ui=new string[s2.length () []; w:for (int x=0;x<s2.length (); x + +) {for (int y=0,z=s2.length () -1-x; z!= S2.length (); y++,z++) {if (S1.contains (s2.substring (y,z+1))) {Op=s2.s                                                Ubstring (y,z+1);                                                                                               Soc (OP);                             breakw;//jump out of the loop immediately after finding}           }} return op;                    public static string Zichuan2 (string s1,string s2) {string max= "";         String min= "";                     Max = (S1.length () <s2.length ())? S2:s1;                           Min = (s1.length () <s2.length ())? S1:s2;                    String op= "";       String[][] Ui=new string[min.length () []; w:for (int x=0;x<min.length (); x + +) {for (int y=0,z=min.length () -1-x; Z!=min.length (); y++,z++)//Definition y indicates on the left, definition Z on the right indicates {                                           if (Max.contains (min.substring (y,z+1))) {                                                Op=min.substring (y,z+1);                                                                                               Soc (OP);                                                                                    Breakw;           }}} return op;             } public static void Soc (Object obj) {System.out.println (obj); }/* the results of the above code compilation Run as follows: qwerqwerc=qwer*/

—————— Split Line ——————

/* StringBuffer The method of the string buffer Note: StringBuilder is jdk1.5 after the appearance, also equivalent to a container, its function and StringBuffer almost, but, StringBuffer is thread-synchronized (the next thread can execute after a thread has finished executing) StringBuilder is a thread that is not synchronized (can be executed concurrently by multiple threads) version upgrade  Factor: Improve efficiency, simplify writing, improve security */class zfclx3{publicstatic void Main (string[] args) {StringBuffer       A=new StringBuffer ();//stringbuffer is a container that can vary in length stringbuffer a2= a.append (26);//Add 26 to the container and return to the container. Soc ("A==a2---" + (A==A2));//Determines whether a and A2 are the same object, prints A==A2---True a.append ("Kaka"). Append (False). Append (1 0);//Call Chain Soc (a);//All are printed as strings of 26 Kaka False10 A.insert (2, "God");//insert operation, Insert Soc on second bit (a);                   /print 26 God Kaka false10//a.insert (200, "God");//corner mark out of Bounds exception a.delete (5,5);//equivalent to No operation                   Soc ("a---------------" +a); Print a---------------26 false10 a.delete (5,7);//Cut 5th to 6th place, note: The seventh-bit SOC is not included ("Cut A=" +a),//print is the cut a=26 God Kaka lse10//a.delete (0,a.length ());//empty buffer (empty container inside) a.                    Deletecharat (2);//Remove the second-character Soc ("A.deletecharat (2)----" +a); A.charat (2);//Gets the second-character//a.indexof ("0");//finds the position of character 0 in the string//a.substring (0,a.length ());// Gets the string from No. 0 to A.length ()-1-bit a.replace (0,3, "KKKK");//Replace the 1th bit in the string with the 2nd bit (excluding the 3rd bit) with the KKKK Soc ("Re         Place---"+a);         StringBuffer a3=new stringbuffer ("HSJD");//The container contains a string HSJD Soc ("a3=" +a3);//Print HSJD SOC2 (A3);                    A3.setcharat (0, ' n ');//The method has no return value and has not returned the SOC (A3.tostring ()) after modification;                          A3.reverse ();//Invert SOC ("Reverse---" +a3);                   StringBuffer a4=new stringbuffer ("abcdefgh");                   Char[] Charsz=new char[8];                   A4.getchars (2,5,charsz,1);       /* Get string 2nd to 4th characters (not including 5th bit)            It then stores the */for (int x=0) starting from the 1th bit of the Charsz array;   x<charsz.length;                                         X + +) {System.out.println ("charsz[" +x+ "]=" +charsz[x]); }} public static void Soc (Object obj) {System.out.println (obj                   ); } public static void Soc2 (Object obj) {stringbuffer a= (stringbuffer) obj;//parent class cast to child               Class A.deletecharat (0);                   System.out.println (a); }/* the above code compile run result: a==a2---true26 kaka false1026 god Kaka false10a---------------26 gods Kaka false10 cut a=26 god Kaka Lse10a.deletecharat (2 )----26 Kaka lse10replace---kkkk lse10a3=hsjdsjdnjdreverse---djncharsz[0]=charsz[1]=ccharsz[2]=dcharsz[3]=echarsz[ 4]=charsz[5]=charsz[6]=charsz[7]=*/

—————— Split Line ——————

/* Object wrapper class for base data type byte Byteshort shortint integerlong longboolean booleanfloat floatdouble Doublechar character*/class zfclx4{publicstatic void Main (string[] args) {s                    OC ("integer.max_value=" +integer.max_value);//print the maximum value of the integer type/* Basic data type to a string:                    Basic data type + "" basic data type. toString (base data type value);                     For example: Integer.tostring (25);        The string is converted to the data type: (except char) XXX a=xxx.parsexxx (string);                               For example: int a= integer.parseint ("26");//numeric string converted to int type data double a=double.parsedouble ("26.23");                               Boolean A=boolean.parseboolean ("true");                                      Short B=short.parseshort ("24"); *///int B=integer.parseint ("m123");//number format exception, run problem//int b=integer.parseint ("0x123") ;//The number format is abnormal, run the problem//iNT B=integer.parseint ("123");//number format exception, run problem//decimal to other binary: String k=integer.tobinarystring (36);      Soc ("integer.tobinarystring" = "+k");       String k2=integer.tohexstring (36);      Soc ("integer.tohexstring" = "+k2");       String k3=integer.tooctalstring (36);                      Soc ("integer.tooctalstring" = "+k3");                   int K6=integer.parseint ("26");                     Soc ("Integer.parseint (\" 26\ ")---" +k6);                   The other binary turns into decimal int x= integer.parseint ("110", 10);        Soc ("Integer.parseint (\" 110\ ", Ten)---" +x);                   int X2=integer.parseint ("110", 2);        Soc ("Integer.parseint (\" 110\ ", 2)---" +x2);                   int X3=integer.parseint ("110", 8);                    Soc ("Integer.parseint (\" 110\ ", 8)---" +x3);                   int x4= Integer.parseint ("110", 16);                    Soc ("Integer.parseint (\" 110\ ",")---"+x4);                   int x5= integer.parseint ("1c", 16); Soc ("Integer.parseint (\" 1c\ ",()---"+x5);         System.out.println ("helloworld!");                 } public static void Soc (String obj) {System.out.println (obj); } */* above code compile run result: integer.max_value=2147483647integer.tobinarystring (=100100integer.tohexstring) (36) = 24integer.tooctalstring ("=44integer.parseint")---26integer.parseint ("ten")---110integer.parseint ("110 ", 2)---6integer.parseint (" 72integer.parseint ", 8)---272integer.parseint (" 1c ")---28Hello world !  */

/*

Basic data type Object wrapper jdk1.5 version new features

*/

Class zfclx5{publicstatic void Main (string[] args) {//integer a= new Integer (12);                   The Integer a=12;//is the same as the previous sentence, but the 12 here is an Object!!! a=a+3;//This sentence compiled run through, here 3 is an int type data,/* This sentence process is this: first a.in                   TValue () +3 then it is assigned to a, then encapsulated as an object */Integer b=145;       Integer c=145;                   Soc ("B==c---" + (b==c)),//b==c---false//object is not the same as Integer b2=127;       Integer c2=127;                    Soc ("B2==c2---" + (B2==C2));//b==c---true//object same/* Why are there two results here?                             Because, in the new feature, if the data does not exceed the byte range and already exists, no new objects will be created if the value exceeds the byte range and already exists, you need to create a new object */         System.out.println ("helloworld!"); } public static void Soc (String str) {System.out.println (str);                 }}  

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Dark Horse programmer--15,string, basic data Type wrapper object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.