当前位置:网站首页>Strings and arrays
Strings and arrays
2022-07-02 15:42:00 【Java land, heaven and man】
character string : It is simply understood as : A string composed of several strings by a signature , It's called string Official understanding : A string is a string of data consisting of multiple characters ( Character sequence ) A string can be thought of as an array of characters ****** Through observation API Find out : 1、String Represents a string . Belong to java.lang It's a bag , Therefore, there is no need to guide the package when using 2、String Class represents string . Java All string text in the program ( for example "abc" ) Are implemented as instances of this class .( object ) 3、 The string doesn't change ; Their values cannot be changed after creation . Strings are constants , Once assigned , The string itself cannot be modified .Construction method : public String() public String(byte[] bytes) Create a string object from a byte array public String(byte[] bytes,int offset,int length) Convert a part of the byte array into a string public String(char[] value) Convert a character array to a string //public String(char[] value,int index,int length) // Convert part of the character array to a string public String(char[] value,int offset,int count) public String(String original)public class StringDemo1 { public static void main(String[] args) { //public String() String s = new String(); System.out.println(s); //String Class toString() // Look at the length of the string //public int length() Returns the length of this string . System.out.println(" character string s The length of is :" + s.length()); // If there are no characters in the string , return 0 // character string s The length of is :0 System.out.println("====================================================="); //public String(byte[] bytes) // Create a string object from a byte array byte[] bytes = {97, 98, 99, 100, 101}; String s2 = new String(bytes); System.out.println("s2: " + s2);//abcde System.out.println(" character string s2 The length of is :" + s2.length());// character string s2 The length of is :5 System.out.println("====================================================="); //public String(byte[] bytes,int index,int length) // Convert a part of the byte array into a string String s3 = new String(bytes, 1, 3); System.out.println("s3: " + s3);//bcd System.out.println(" character string s3 The length of is :" + s3.length());//3 System.out.println("====================================================="); //public String(char[] value) // Convert a character array to a string char[] c = {'a', 'b', 'c', 'd', ' I ', ' Love ', ' feng ', ' carry ', ' No '}; String s4 = new String(c); System.out.println("s4: " + s4);//abcd I love von Timo System.out.println(" character string s4 The length of is :" + s4.length());//9 System.out.println("====================================================="); //public String(char[] value,int index,int length) // Convert part of the character array to a string String s5 = new String(c, 4, 5); System.out.println("s5: " + s5);// I love von Timo System.out.println(" character string s5 The length of is :" + s5.length());//5 System.out.println("====================================================="); //StringIndexOutOfBoundsException // String s6 = new String(c,4,10); // System.out.println("s6: "+s6); // System.out.println(" character string s5 The length of is :" + s6.length()); System.out.println("====================================================="); //public String(String original) String s7 = " Hello "; String s8 = new String(s7); System.out.println("s8: " + s8);// Hello System.out.println(" character string s8 The length of is :" + s8.length());//2 } }
ring(String original)
边栏推荐
- Loss function and positive and negative sample allocation: Yolo series
- fastjson List转JSONArray以及JSONArray转List「建议收藏」
- SQL FOREIGN KEY
- Folium, diagnosis and close contact trajectory above
- 2278. 字母在字符串中的百分比
- PTA ladder game exercise set l2-001 inter city emergency rescue
- [leetcode] 977 - carré du tableau ordonné
- 2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
- 二叉树前,中,后序遍历
- 2278. Percentage of letters in string
猜你喜欢
[network security] network asset collection
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
Loss function and positive and negative sample allocation: Yolo series
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
Wechat Alipay account system and payment interface business process
Soul torture, what is AQS???
树-二叉搜索树
[development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
SQL transaction
随机推荐
beforeEach
Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)
Custom exception
《大学“电路分析基础”课程实验合集.实验七》丨正弦稳态电路的研究
List of sergeant schools
[leetcode] 283 move zero
Bing. Com website
【LeetCode】1905-统计子岛屿
[leetcode] 189 rotation array
使用FFmpeg命令行进行UDP、RTP推流(H264、TS),ffplay接收
6096. 咒语和药水的成功对数
2303. Calculate the total tax payable
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
睿智的目标检测23——Pytorch搭建SSD目标检测平台
Loss function and positive and negative sample allocation: Yolo series
【LeetCode】977-有序數組的平方
6090. Minimax games
制作p12证书[通俗易懂]
Engineer evaluation | rk3568 development board hands-on test
[leetcode] 977 - carré du tableau ordonné