前情提要: 在第七天我们透过比较Symbol和String,发现字串比符号多了更多方法!为了活用string method,今天我们接续前文,来探讨一题跟字串有关的题目: Ruby经典面试题目#08(leafor)+=和concat有什么不同?What’s difference between concat and +=? concat是英文concatenate的缩写,意思是串接(link things together in a chain or series.)我们想知道的是:串接完之后,…
前情提要: 第六天我们透过Ruby代码练习public,protected和privatemethod时,发现冒号在前面的参数,:mydraft,:myspace,这些就是符号Symbol.在今天,我们就来解释Symbol吧! Ruby经典面试题目#07符号和字串有什么不同?What’s difference between symbol and string? 还记得我之前IT邦文章在Ruby on Rails项目例子中研究ruby的gem套件时,我发现这两者写法的功能是一样的: :image…
1:将string转化为int 1.) int i = Integer.parseInt(String s); 2.) int i = Integer.valueOf(my_str).intValue(); 他们有着本质的区别: Integer.parseInt(String s);它的作用是将形参 s 转化为Integer对象(包装类) Interger.valueOf("123")=Integer(123) 这时候Integer(123)就是整数123的对象表示形式, 它再调用in…
int -> String int i=12345;String s="";第一种方法:s=i+"";第二种方法:s=String.valueOf(i);这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢? String -> int s="12345";int i;第一种方法:i=Integer.parseInt(s);第二种方法:i=Integer.valueOf(s).intValue();这两种方法有什么区别…