public class Test{ public static void main(String[] args) { String s="hello jack hello look me to see nohello"; String target="hello";//甚至可以为正则表达式 int count=0; while(s.indexOf(target)>=0){ s=s.replaceFirst(target, ""); Sys…
用代码演示String类中的以下方法的用法 (1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true (2)char charAt(int index): 返回索引上的字符 (3)String toLowerCase(): 字符串转成小写 (4)String toUpperCase(): 字符串转成大写 (5)String repalce(char oldChar, char newChar): 将字符串中的老字符,替换为新字符 (6)String repalc…
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public static void main(String args[]) { String str = "helloworld"; // 字符串对象 if (str.indexOf("world") != -1) { // 能找到子字符串 System.out.println(…
String类的定义:    java.lang  类 String   java.lang.Object      java.lang.String 所有已实现的接口:Serializable, CharSequence, Comparable<String> public final class String      extends Objectimplements Serializable, Comparable<String>, CharSequenceString 类代…
今天在看一本书的时候注意到一个String的intern()方法,平常没用过,只是见过这个方法,也没去仔细看过这个方法.所以今天看了一下.个人觉得给String类中加入这个方法可能是为了提升一点点性能,因为从常量池取数据比从堆里面去数据要快一些.(个人感觉) API上的那几句关于这个方法,其实总结一句就是调用这个方法之后把字符串对象加入常量池中,常量池我们都知道他是存在于方法区的,他是方法区的一部分,而方法区是线程共享的,所以常量池也就是线程共享的,但是他并不是线程不安全的,他其实是线程安全的,…
1.字符串与字符数组的转换 字符串可以使用toCharArray()方法变成一个字符数组,也可以使用String类的构造方法把一个字符数组变成一个字符串. public class StringAPIDemo01 { public static void main(String[] args) { String str1 = "hello"; //定义字符串 char c[] = str1.toCharArray(); //将字符串变为字符数组 for(int i=0;i<c.l…
一.Java下 1.几个例子 public static void main(String[] arge) { String str1 = new String("1234"); String str2 = new String("1234"); System.out.println("①new String()方式下==:" + (str1 == str2)); System.out.println("②new String()方式下…
一.获取: 1.获取字符串的长度(注意是方法,不是跟数组的属性一样的) int length(); 1 public static void getLength(){ 2 String s = "java01"; 3 int len = s.length(); 4 System.out.println(len); 5 } 2.根据位置,获取该位置的那一个字符(只能是单个字符) char charAt(int index); 1 //根据指定位置获取对应的那个字符,只能是一个字符不能是字…
1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String],[int radix]); 2). int i = Integer.valueOf(my_str).intValue(); 注: 字串转成 Double, Float, Long 的方法大同小异. 2 如何将整数 int 转换成字串 String ? A. 有叁种方法: 1.) St…
我们用一个经典的例子来理解 package com.jvm.heap; public class MyTest { public static void main(String[] args) { String str1 = new StringBuilder("计算机").append("软件").toString(); System.out.println(str1.intern() == str1); String str2 = new StringBuild…