![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
字符串
爱读书的男孩子9420
这个作者很懒,什么都没留下…
展开
-
字符串中,字符及一段字符的所在位置(索引)
package wfh7_21; public class index { public static void main(String[] args) { String str1 = "abcdefg"; int x = str1.indexOf("c"); int y = str1.indexOf("de"); //从0开始算起 System.out.println(x+" "+y);//"c"和"de"的所在位.原创 2020-07-21 17:12:18 · 947 阅读 · 0 评论 -
字符串大小的比较
package basic; public class StringTest { public static void main(String[] args) { int result1 = "abc".compareTo("abc");//( ascii )比较,小于参数为负,大于参数为正,等于参数0。()里面的为参数 int result2 = "abc".compareTo("aac"); int result3 = "abc".compareTo(.原创 2020-07-19 19:51:17 · 179 阅读 · 0 评论 -
字符串的输出及连接
package basic; public class StringTest { public static void main(String[] args) { String str2 = "123".concat("456"); System.out.println(str2); String str3 = 1 + 2 + 3 + "123";//结果为6123, String str4 = "123" + 1 + 2 + .原创 2020-07-19 19:40:51 · 324 阅读 · 0 评论 -
输出字符串长度及所有字符
package basic; public class StringTest { public static void main(String[] args) { String str1 = "my name is wfh"; System.out.println(str1.length()); for (int i = 0; i < str1.length(); i++) { System.out.print(str.原创 2020-07-19 16:40:36 · 325 阅读 · 0 评论