Browsing 7239 questions and answers with Jon Skeet

Java not recognizing elements in ArrayList?

I have a program where I make an arraylist to hold some cab objects. I keep getting an error that what I get from the message is that java does not recognize that the arraylist...
Jon Skeet
people
quotationmark

The list isn't populated with an element at item count. Look at the exception: you've got 20 elements in the list, so the valid indexes are 0 to 19 inclusive. You're asking for record 20 (i.e. the 21st record). That doesn't exist. It... more 10/1/2014 1:05:57 PM

people

Processes in Java Do they work concurrently?

I am executing another java program through a Process object. This takes some time to complete. In the mean time, will the parent program continue running or will it be on hold,...
Jon Skeet
people
quotationmark

It will execute separately unless you either block waiting for data from the other process (e.g. calling Process.getInputStream() and then reading from it), or call Process.waitFor(). The second process has its own threads - these are not... more 10/1/2014 6:01:06 AM

people

Parsing an ISO string in UTC to DateTimeKind.UTC

Let's say, I have a string like this - "2014-09-30T20:38:18.280", how can I parse this into a DateTime field of DateTimeKind.Utc. When I perform...
Jon Skeet
people
quotationmark

Specify DateTimeStyles.AssumeUniversal when you parse. If no time zone is specified in the parsed string, the string is assumed to denote a UTC. I'd also use DateTime.ParseExact and specify the invariant culture: var time =... more 9/30/2014 10:00:55 PM

people

How to use lambda expressions for a function that takes a list of delegates

I'm building an extension method on IList to be able to output the specified properties of any object passed into it as a list, and output it as a CSV string. It looks...
Jon Skeet
people
quotationmark

Rather than using a List<Func<T, string>> use a Func<T, string>[] and make it a parameter array: static string OutputCSVString<T>(this IList<T> list, params Func<T,... more 9/30/2014 9:12:45 PM

people

Do both of these constructors do the same thing?

Do both of these code blocks do the same thing? class A { public static int s; A(){} static A(){s = 100;} } and class A { public static int s=100; A(){} ...
Jon Skeet
people
quotationmark

No, they don't behave quite the same way. Without the static constructor, the timing of exactly when the type initializer executes is much looser - it can happen earlier or later than you'd expect. When there's a static constructor, the... more 9/30/2014 4:36:11 PM

people

Re format datetime to 7th November 2014

I have myself a DateTime variable of 7/11/2014 and I want to convert that date to display as 7th November 2014 What format do I use? I have tried ToLongDateString but it...
Jon Skeet
people
quotationmark

I don't believe there's any direct support for ordinals ("st", "nd", "th") within .NET. If you only need to support English, I suggest you hard code it yourself. For example: string text = string.Format("{0}{1} {2} {3}", dt.Day,... more 9/30/2014 3:11:39 PM

people

Usefulness of HashMaps in Java

So I was working on a programming challenge where I wanted to store more than 128 key-value pairs of type <int, int>. Since HashMaps can't accept primitives, I used...
Jon Skeet
people
quotationmark

This will cause a NullPointerException because the HashCode of the x and y are different (which is expected because the Integer class keeps a cache of values only between -128 and 127). That's irrelevant. Integer overrides hashCode()... more 9/30/2014 5:51:25 AM

people

BigInteger(long) has private access in BigInteger

I am trying to store a big calculation in a BigInteger instance. I tried this : BigInteger answer=new BigInteger(2+3); and got the following error : temp.java:17: error:...
Jon Skeet
people
quotationmark

If you want to perform the arithmetic using BigInteger, you should create a BigInteger for each value and then use BigInteger.add. However, you don't need to use strings to do that. You may want to if your input is already a string and it... more 9/29/2014 4:13:20 PM

people

Can I use the Debug\program.exe as a standalone?

I wanted to create a portable application (without installers), but as far as I know there is no way to export an executable in vs2013, only a setup. So I was wondering if it is...
Jon Skeet
people
quotationmark

It depends on what your app uses. If there are extra references which are being copied into your bin directory, you'd need to copy those as well. Likewise if you have other content being copied into the output directory. But yes, if you... more 9/29/2014 9:45:21 AM

people

Getting dynamic property value via string

I have a dynamic object that is generated from WebMatrix.Data: dynamic obj; [WebMatrix.Data.DynamicRecord] So doing something like this is fine: int ID = obj.ID; However,...
Jon Skeet
people
quotationmark

I'm guessing that's why the error, but why is it null when obj.ID does not return null? GetProperty() will look for a CLR property on the type. That's not always how a dynamic property access works - DynamicRecord derives from... more 9/29/2014 8:09:32 AM

people