当前位置:网站首页>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)
边栏推荐
- College entrance examination admission score line climbing
- 《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
- 夏季高考文化成绩一分一段表
- [leetcode] 200 number of islands
- 【LeetCode】486-预测赢家
- fastjson List转JSONArray以及JSONArray转List「建议收藏」
- 6095. 强密码检验器 II
- /bin/ld: 找不到 -lpam
- Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
- 03.golang初步使用
猜你喜欢

【LeetCode】1162-地图分析

Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)

PTA ladder game exercise set l2-001 inter city emergency rescue

LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
![[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)](/img/cf/38e4035c3b318814672f21c8a42618.jpg)
[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)

Basic knowledge of cryptography

Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568

Leetcode skimming -- count the number of numbers with different numbers 357 medium

MySQL calculate n-day retention rate

Pytoch saves tensor to Mat file
随机推荐
Redux——详解
The task cannot be submitted after the installation of flick is completed
2303. 计算应缴税款总额
C # get PLC information (kepserver) II
【LeetCode】1162-地图分析
夏季高考文化成绩一分一段表
6090. 极大极小游戏
Beijing rental data analysis
Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
士官类学校名录
6095. Strong password checker II
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
【LeetCode】417-太平洋大西洋水流问题
[leetcode] 1254 - count the number of closed Islands
彻底弄懂浏览器强缓存和协商缓存
目标检测—利用labelimg制作自己的深度学习目标检测数据集
Bing.com網站
[leetcode] 977 - carré du tableau ordonné
Leetcode skimming -- sum of two integers 371 medium
folium,确诊和密接轨迹上图