Browsing 7239 questions and answers with Jon Skeet

Java ListIterator clarification

I am working on implementing a method that checks for number of max number consecutive equal elements in an ArrayList: public class ArrayReader<E> { public int...
Jon Skeet
people
quotationmark

However, the output I am getting indicates that it isn't truly comparing the current element to the next Indeed, it will be comparing one item with itself in each case. After all, you start with index = 0 and on the first iteration... more 2/10/2016 9:26:01 AM

people

IOUtils.toString taking to long

I have this class which opens a HTTP-Server and listens on a port. The reply is a http-header plus a json object. The class takes the input stream from the server, converts it to...
Jon Skeet
people
quotationmark

You're not measuring what you think you are. Here: System.out.println("Start get From Socket " + System.currentTimeMillis()); InputStream mis = socket.getInputStream(); System.out.println("Stop get From Socket ... more 2/9/2016 5:24:02 PM

people

Is a String generic parameter treated as a value type or reference type?

From the MSDN Generics in the Run Time document I note: When a generic type is first constructed with a value type as a parameter, the runtime creates a specialized generic...
Jon Skeet
people
quotationmark

string is a reference type in every way. It has "value-type semantics" in the Wikipedia sense, but that doesn't make it a value type in the terminology used in MSDN. In the common CLR and C# terminology which divides all non-pointer types... more 2/9/2016 2:14:34 PM

people

Reading the values from and Writing to the XML File in C#

I want to read the values from the XML file after doing some modifications and I want to write it to the same file. Note:- It should not read the commented values from...
Jon Skeet
people
quotationmark

You're never closing the XmlReader, so it's still got an open file handle for reading - which means you can't write to the same file. You should put it in a using statement: var doc = new XmlDocument(); var settings = new... more 2/9/2016 1:53:33 PM

people

vertex 3.x fetch timezone from http request

I am using vertex 3.x. I have a requirement to access timezone from HttpServerRequest object to provide timezone based data to user.
Jon Skeet
people
quotationmark

It doesn't have one, basically. There's nothing in a regular HTTP request to identify the time zone. Your options are: Use an IP geocoding API to guess at the user's location, followed by a location-to-timezone conversion (e.g. through... more 2/9/2016 7:08:16 AM

people

C# use Linq to pull data from xml

I have problem with building object holding XML data using Linq. For example, I have XML data in url http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30000142 ....
Jon Skeet
people
quotationmark

You're looking for an element called "type id". That's not a valid name for an element in XML. You should just look for elements called type... that's the name of this element: <type id="34"> If you want to filter by ID, you could... more 2/8/2016 4:34:01 PM

people

keyword 'this' shown as a variable name

I am a beginner in java coding and I am having a hard time understanding the below scenario. Below is the screen shot of eclipse, while I was trying to debug my program. I could...
Jon Skeet
people
quotationmark

From section 15.8.3 of the JLS: When used as a primary expression, the keyword this denotes a value that is a reference to the object for which the instance method or default method was invoked (ยง15.12), or to the object being... more 2/8/2016 1:11:43 PM

people

How to parse String as Binary and convert it to UTF 8 equivalent in Java?

I need to parse String content as binary sequence and convert them to its UTF-8 equivalent String. For example, UTF-8 binary equivalents of B, A and R are as follows: B...
Jon Skeet
people
quotationmark

You should separate this into two problems: Converting the string into a byte array by parsing the binary values Converting the byte array back into a string using UTF-8 The latter is very straightforward, using new String(bytes,... more 2/8/2016 7:18:01 AM

people

Java Arrays Do each element in array hold pointer to the next element

Java LinkedList class uses doubly linked list to store the elements. Does Arrays in Java use singly-linked list ? Is this how array and stacks are different in java.
Jon Skeet
people
quotationmark

No. An array is just a contiguous block of memory, with a length that can be checked to make sure you don't try to access elements outside the array's bounds. To get to a specific element, the VM just (logically, at least) takes the start... more 2/6/2016 10:36:26 AM

people

Convert to Nullable Decimal in Expression Trees

My models have Nullable decimal types. So in my Expression trees it gave me the following error: The binary operator Equal is not defined for the types ...
Jon Skeet
people
quotationmark

The normal C# code example you've shown has converted to decimal?, using the implicit conversion from T to T? for any non-nullable value type T. In an expression tree, you just need to use Expression.Convert to perform that conversion,... more 2/6/2016 8:17:16 AM

people