Browsing 7239 questions and answers with Jon Skeet

Looping with ArrayList

I have this code that involves task to do with the ArrayList names that includes functions like adding elements in the ArrayList, displaying the elements of the ArrayList,...
Jon Skeet
people
quotationmark

Each time you call menuCaller, you're creating a new list. Perhaps you should create it in the main method and pass the reference into menuCaller: public static void main(String[] args) { String con; List<String> names =... more 6/22/2015 12:51:18 PM

people

Convert contents of an XmlNodeList to a new XmlDocument without looping

I have Xml that I filter using XPath (a query similar to this): XmlNodeList allItems = xDoc.SelectNodes("//Person[not(PersonID = following::Person/PersonID)]"); This...
Jon Skeet
people
quotationmark

If you're happy to convert it into LINQ to XML, it's really simple: XDocument original = ...; // However you load the original document // Separated out for clarity - could be inlined, of course string xpath = "//Person[not(PersonID =... more 6/22/2015 9:04:51 AM

people

Is timezone info redundant provided that UTC timestamp is available?

I have a simple mobile app that schedules future events between people at a specified location. These events may be physical or virtual, so the time specified for the event may or...
Jon Skeet
people
quotationmark

For a single event, knowing the UTC instant on which it occurs is usually enough, so long as you have the right UTC instant (see later). For repeated events, you need to know the time zone in which it repeats... not just the UTC offset,... more 6/22/2015 8:23:50 AM

people

error accessing 2d array with c#

I am new to Unity3D and c#. I am tinkering with storing some grid positions within a 2d array however I've run into the array index is out of range error and I don't know...
Jon Skeet
people
quotationmark

You have a 2D array which is 6x2 - not one which is 2x6. Each "subarray" you're specifying in the initialization is one "row", if you think of accessing the array by array[row, column]. So for example, myArray[0, 1] is 375 - the second... more 6/22/2015 5:46:14 AM

people

OutputStream class is used for writing into files. How is it possible?

The below code is quoted from : http://examples.javacodegeeks.com/core-java/io/fileoutputstream/java-io-fileoutputstream-example/ Although the OutputStream is an abstract method,...
Jon Skeet
people
quotationmark

Just because the declared type is OutputStream, that doesn't mean the implementation doesn't create an instance of a concrete subclass of OutputStream. You see this all the time with interfaces. For example: public List<String>... more 6/21/2015 7:32:43 PM

people

Get element based on string

I am creating a web api using mvc 6. now i am trying to get a element from my db. the key in this table is a string (email address). I do not have access to this database so i...
Jon Skeet
people
quotationmark

Just remove :string. You're not really constraining the value of the id anyway - it's already a string in the URL. This fairly old blog post lists the available constraints - and you can see there's no :string constraint, because you... more 6/20/2015 7:55:23 AM

people

Immutable type wrapper

I'm confused about Type wrappers being immutable when executing following code static void inc(Integer nr) { System.out.printf("1. inc() \t %d \n", nr); nr++; ...
Jon Skeet
people
quotationmark

If a type wrapper is immutable, why then is the value increased between line "1. inc" and "2. inc" Because you're not actually mutating the existing Integer object - you're creating a new one (well, effectively - actually it'll use... more 6/19/2015 3:29:37 PM

people

How do I get the date of 31 days ago?

How can I get x which should be 31 days before current_date? x(date)___________________________current_date 31
Jon Skeet
people
quotationmark

Just subtract 31 days. For example: LocalDate current = new LocalDate(2015, 6, 19); LocalDate x = current.minusDays(31); // 2015-05-19 To get the current date, you could use: LocalDate current = new LocalDate(); // Default time... more 6/19/2015 8:00:52 AM

people

Java unexpected character parsing txt file

I am trying to divide txt files into ArrayList of strings and so far it works, but first words in the file always starts with (int)'65279' and I can't even copy this character...
Jon Skeet
people
quotationmark

U+FEFF is the byte order mark. It's used to indicate the character encoding/endianness (to you can easily tell the difference between big and little-endian UTF-16, for example). If it's causing you a problem, the simplest thing is just to... more 6/19/2015 7:48:17 AM

people

pretend to have a file without loading it from harddrive

How to pretend to have a file without actually loading a file? The challenge is not to create a temporary file or load anything from a harddrive. I would rather like to keep...
Jon Skeet
people
quotationmark

A memory stream isn't a file. It's just data. The concept of setting a filename and extension on a memory stream simply doesn't make sense - any more than it would for a byte[]. more 6/19/2015 6:26:44 AM

people