import java.util.ArrayList;
import java.util.List;
public class TestSubstring {
public static void main(String[] args) {
List<String> handler =new ArrayList<String>();
int j = 0;
for (int i = 0; i < 1000; i++) {
j++;
HugeStr h = new HugeStr();
handler.add(h.getSubString(1,5));
System.out.println(j);
}
}
static class HugeStr{
private String str=new String(new char[100000]);
public String getSubString(int begin,int end){
return str.substring(begin, end);
}
}
static class ImprovedHugeStr{
private String str=new String(new char[100000]);
public String getSubString(int begin,int end){
return new String(str.substring(begin, end));
}
}
}
substring 导致内存溢出
最新推荐文章于 2022-11-02 09:55:47 发布