Browsing 7239 questions and answers with Jon Skeet

Callable sequential execution

I know Callable allows to return a value or checked exception whereas Runnable doesn't. This question is not about the difference between the two interfaces but about the...
Jon Skeet
people
quotationmark

So my question is why does the fist code segment with futures and callable response is always sequential? Because you're specifically asking for the result of the Futures in the order in which they were submitted: for... more 2/4/2015 3:16:34 PM

people

Is it safe (in matter of uniqueness) to use UUID to generate a unique identifier for specific string?

String myText; UUID.nameUUIDFromBytes((myText).getBytes()).toString(); I am using above code to generate a representative for specific texts. For example 'Moien' should always...
Jon Skeet
people
quotationmark

UUID.nameUUIDFromBytes appears to basically just be MD5 hashing, with the result being represented as a UUID. It feels clearer to me to use a base64-encoded hash explicitly, partly as you can then control which hash gets used - which... more 2/4/2015 2:42:21 PM

people

cannot do join in Linq properly

I am very new at Linq. I am trying to do Linq JOIN in my project but I cannot do it properly. No data comes out of the Linq statement. Would you please give me a hint for...
Jon Skeet
people
quotationmark

Your first join doesn't use c at all. This: join c in db.AY_COMPANIES on cbr.COMPANY_ID equals ID should almost certainly be join c in db.AY_COMPANIES on cbr.COMPANY_ID equals c.ID (or whatever the ID should map to within... more 2/4/2015 1:38:18 PM

people

In Java 8, transform Optional<String> of an empty String in Optional.empty

Given a String I need to get an Optional, whereby if the String is null or empty the result would be Optional.empty. I can do it this way: String ppo = ""; Optional<String>...
Jon Skeet
people
quotationmark

How about: Optional<String> ostr = ppo == null || ppo.isEmpty() ? Optional.empty() : Optional.of(ppo); You can put that in a utility method if you need it often, of course. I see no benefit in creating an Optional with an... more 2/4/2015 1:22:22 PM

people

How to get event name in event handler

I'm curious if is possible to get event name in event handler? I'm pretty sure, that it's possible, can you help me find solution? Ex: public class Boy { public event...
Jon Skeet
people
quotationmark

I'm curious if is possible to get event name in event handler? No, it's not. The event handler is just a method. It could be invoked directly, not in the context of any event. What you could do is have: public Mother() { Boy son... more 2/4/2015 11:57:15 AM

people

How to convert Linq.IEnumerable(Of String) to formatted Strings

I have a List(Of String) that stores validation errors. Should that list contain any items, I'd like to concatenate them into an HTML list to show each error. Currently this is...
Jon Skeet
people
quotationmark

It sounds like you need a combination of Join and Select: String.Join("", _ l.Select(Function(s as String) String.Format("<li>{0}</li>", s)) Of course, you could always write your own JoinFormat extension method - that... more 2/4/2015 11:32:45 AM

people

SimpleDateFormat shows time in 24 hours even after using "hh" for hour

Accoridng to SimpleDateFormat, if i will use hh for hour, then i will get time in AM/PM, so I am trying this, SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy hh:mm:ss...
Jon Skeet
people
quotationmark

but the output of above parsed date is still in 24 hours format instead of 12 hours AM/PM. You've parsed the value using hh, but the output is just what you get from calling Date.toString(): Converts this Date object to a String... more 2/4/2015 10:12:17 AM

people

C# repeating IEnumerable multiple times

How to repeat whole IEnumerable multiple times? Similar to Python: > print ['x', 'y'] * 3 ['x', 'y', 'x', 'y', 'x', 'y']
Jon Skeet
people
quotationmark

You could use plain LINQ to do this: var repeated = Enumerable.Repeat(original, 3) .SelectMany(x => x); Or you could just write an extension method: public static IEnumerable<T> Repeat<T>(this... more 2/4/2015 8:25:33 AM

people

ArrayList IndexOutOfBoundsException despite adding within the capacity of the list

I have following code public static void main(String[] args) { List<Integer> list = new ArrayList<>(); list.add(1, 555); } and it is initialize with 10...
Jon Skeet
people
quotationmark

it is initialize with 10 elements No, it isn't. It's initialized with an internal buffer size of 10, but that's largely an implementation detail. The size of the list is still 0, as you can confirm by printing out list.size() before... more 2/4/2015 7:04:21 AM

people

Is there any way to assign diffrent type variables in single statement..?

I am thinking is there any way to assign different type of variables in single statement..? string s = ""; int ia = 0; int ib = 5; // is there any short hand technique to...
Jon Skeet
people
quotationmark

You can do this: string s = ""; int ia = 0; int ib = 5; s = (ia = ib).ToString(); I wouldn't recommend it, but it will work - ia will be 5, and s will be "5". Would you really rather do that than use two statements though? I try to... more 2/4/2015 7:01:10 AM

people