From: "Matthias Wächter" Date: 2011-11-28T23:49:40+09:00 Subject: Re: Is high-speed sorting impossible with Ruby? On 28.11.2011 15:17, Gaurav C. wrote: > What's the difference between Array.new(1e6+1) {|n| ""} and > Array.new(1e6+1, "")? The first one creates one array with 1e6+1 _different_ empty strings. The second one results in an array that holds 1e6+1 references to the _same_ empty string. Note that the following code variants both work as expected: > a = Array.new(1e6+1) {""} > > … > a[l.to_i] << l > … > a = Array.new(1e6+1, "") > > … > a[l.to_i] += l > … but not this one: > a = Array.new(1e6+1, "") > > … > a[l.to_i] << l > … String#+ creates a new string object while String#<< modifies the current string object. – Matthias