Browsing 7239 questions and answers with Jon Skeet
It sounds like you just need Math.min a couple of times: int start = Math.min(index, s.length()); int end = Math.min(index + length, s.length()); return s.substring(start, end); more 4/12/2015 8:13:30 PM
Does java have a data structure that does NOT allow duplicates or palindromes? Well Java has a number of sets - HashSet, for example. Those don't allow multiple equal values to be stored... so you just need to create a class which... more 4/12/2015 2:14:46 PM
Here's a demonstration: import java.io.*; class ClassSingleton implements Serializable { public static final ClassSingleton INSTANCE = new ClassSingleton(); private ClassSingleton() {} } enum EnumSingleton { ... more 4/12/2015 6:40:23 AM
Yes, those are overloads. From JLS 8.4.9: If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but signatures that are not... more 4/11/2015 6:28:03 PM
It's not a warning - it's an error. There are two facts at work here: There's no short + short operator; the "smallest" addition is int + int, with a result type of int, and the operands are automatically promoted to int if necessary... more 4/11/2015 2:02:58 PM
Assuming you only want types from mscorlib, it's easy: var mscorlib = typeof(string).Assembly; var types = mscorlib.GetTypes() .Where(t => t.Namespace == "System"); However, that won't return byte[], as that's an... more 4/9/2015 5:44:52 PM
Is there a possibility to translate this method chain to LINQ? (By "to LINQ" I believe you mean "to query expression syntax".) Not directly, no. Effectively, you can only convert expression-bodied lambda expressions into query... more 4/9/2015 3:03:35 PM
For each pair of threads, if thread A manages to acquire the lock before thread B, you'll end up with both threads completing, and everything can be cleaned up. If thread B manages to acquire the lock before thread A, thread B will... more 4/9/2015 2:47:03 PM
You absolutely can remove from a list containing a null reference - you just can't call equals on a null reference. The problem is here: if(a.equals(32)) That will fail with a NullPointerException if a is null. There's nothing... more 4/9/2015 2:25:25 PM
Look at this condition: if (inps.charAt(i) != ' ' || inps.charAt(i) != '\t') That will pass if the character isn't space or if it isn't tab. A single character can't be both space and tab, so at least one of the subconditions will be... more 4/9/2015 6:50:50 AM