当前位置:网站首页>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)
边栏推荐
猜你喜欢

动态规划入门一,队列的bfs(70.121.279.200)
![[experience cloud] how to get the metadata of experience cloud in vscode](/img/45/012c2265402ba1b44f4497f468bc61.png)
[experience cloud] how to get the metadata of experience cloud in vscode

【Salesforce】如何确认你的Salesforce版本?

PTA 天梯赛习题集 L2-001 城市间紧急救援

全是精华的模电专题复习资料:基本放大电路知识点

Beijing rental data analysis

使用 percona 工具给 MySQL 表加字段中断后该如何操作

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

Bing.com网站

4. Jctree related knowledge learning
随机推荐
6096. Success logarithm of spells and potions
【LeetCode】486-预测赢家
全是精华的模电专题复习资料:基本放大电路知识点
folium,确诊和密接轨迹上图
Leetcode skimming -- sum of two integers 371 medium
lseek 出错
4. Jctree related knowledge learning
【LeetCode】1162-地图分析
党史纪实主题公益数字文创产品正式上线
Redux - detailed explanation
LeetCode刷题——去除重复字母#316#Medium
士官类学校名录
数组和链表的区别浅析
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
03. Preliminary use of golang
SQL FOREIGN KEY
02. After containerization, you must face golang
【idea】推荐一个idea翻译插件:Translation「建议收藏」
Two traversal sequences are known to construct binary trees
6090. 极大极小游戏