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 ());}}