在java中,try ...catch...finally 这个知识点说简单也简单,毕竟只是一个固定结构;说难也难,因为它会出现我们意想之外的结果,这里我摘录些可能出现问题的情况:
情况一:
public class TestTryReturn {
public static void main(String[] args){
TestTryReturn ttr = new TestTryReturn();
System.out.println(ttr.launch());
}
public int launch(){
try{
System.out.println("run in try region");
return 0;
}catch(Exception e){
e.printStackTrace();
System.out.println("run in catch re......
阅读全文
java中substring的用法
str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;
str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;
以下是一段演示程序:
public class StringDemo{
public static void main(String agrs[]){
String str="this is my original string";
String toDelete=" original";
if(str.startsWith(toDelete))
str=str.substring(toDelete.length());
else
......
阅读全文