String, stringbuilder method, pseudo-random class

Source: Internet
Author: User
Import Java. NIO. charset. charset; public class stringdemo {public static void main (string [] ARGs) {byte [] bt = {'A', 'B', 'C '}; // string (byte [] BT, charset); // This constructor constructs a New String object charset = charset Based on the given byte array and character set. forname ("UTF-8"); string S1 = new string (BT, charset); system. out. println (S1); system. out. println (s1.charat (1); string S2 = "ABCDE"; // The first half of S2 is S1. The compareto method returns the length difference between the two strings. system. out. println (s1.compareto (S2); // S1, S3 starts from 0 (A), returns the first unequal character difference (the difference between B and) string S3 = "AAC"; system. out. println (s1.compareto (S3); // Concat string connection, same as + system. out. println (s1.concat (S2); system. out. println (s1.concat (S2 ). endswith (S2); system. out. println (s1.20.signorecase ("ABC"); byte [] BB = s1.getbytes (); char [] CH = new char [s1.length ()-1]; system. out. println (char) bb [1]); s1.getchars (0, s1.length ()-1, CH, 0); system. out. println (s1.replace ('A', 'A'); system. out. println (S1 );}}

Stringbuilder

public class BuilderDemo {    public static void main(String[] args) {        StringBuilder sb=new StringBuilder();        sb.append(" here ");        sb.append("am ");        sb.append("I ");        System.out.println(sb);        sb.insert(5," here");        System.out.println(sb);        System.out.println(sb.reverse());        sb.delete(2,3);        sb.setLength(5);        System.out.println(sb.length());        System.out.println(sb.capacity());    }}
Public class randdemo {public static void main (string [] ARGs) {random Rand = new random (100); system. out. println (Rand. nextboolean (); system. out. println (Rand. nextint (); random rand2 = new random (100); // The running result of rand2 Rand is the same as that of system. out. println (rand2.nextint (); system. out. println (rand2.nextboolean ());}}

 

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.