Browsing 7239 questions and answers with Jon Skeet

Find contained string in a string and get it's ending index value

I'm trying to store unknown amount of specific strings inside a string but I want to get it's index so I can check it again. For example: List<string> values = new...
Jon Skeet
people
quotationmark

This looks like a good place to use regular expressions (and that's not something I say often). For example: using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { var regex... more 10/5/2014 7:24:30 AM

people

HashMap adding all items even when duplicate

I have been trying without any luck to make a list of all points in a model. When i execute this HashList<Point> points=new HashList<Point>(16); //add +y...
Jon Skeet
people
quotationmark

The problem is your finally block in equals(Object). It's always returning false, even if you're returning true from the try block. You're getting confused because of this: boolean equals=a.equals(b); //true ... but that's not calling... more 10/5/2014 3:13:11 AM

people

How to remove xml element in windows phone

After I could create an xml, and adding data and element to it, I want to be able to remove a specific element from it as well. I tried to follow what it said from here Deleting...
Jon Skeet
people
quotationmark

You're currently reusing the same stream to save over the top. That will only overwrite data - it won't truncate the file at the end point of your document. What you really want to do is effectively create a new file. Something like: var... more 10/4/2014 4:47:48 PM

people

Convert generic extension function to simple legacy one

First of all i have some legacy .NET 2 code and i need to transform a extension function to a simple function. So i will start from what i want to achieve. I have two object...
Jon Skeet
people
quotationmark

And the only thing i want to do is this: var y = Concat(a, b); and then return an array. You can't do that unless you're within the same class as the method (or a subclass). You can stop it being an extension method just by removing... more 10/4/2014 4:39:32 PM

people

Java inner classes & inheritance: Is there a duplicate outer this reference?

Consider this scenario with inner classes and inheritance: class X{ class A{ X foo(){ return X.this; // outer this reference to X returned } ...
Jon Skeet
people
quotationmark

You can use javap to find out what fields a class has. (This is up to the compiler, not the JVM.) In this case: C:\Users\Jon\Test>javap -p Y$B Compiled from "Test.java" class Y$B extends X$A { final Y this$0; Y$B(Y); Y foo(); X... more 10/4/2014 2:49:51 PM

people

Java Array Custom Function

I want to convert a Vector3f array directly from array to another kind of data. Here is an example: Vector3f[] vecArray = new Vector3f[10]; float[] floatArray =...
Jon Skeet
people
quotationmark

No, there's nothing you can do to make that compile. (There's no equivalent of the extension methods in C# which would allow it, for example.) The closest you'd be able to come would be to have a static method somewhere - whether within... more 10/4/2014 1:36:53 PM

people

Java: why 7 / 3 is 2?

Why in java 7 / -3 isn't -3? It is -2. I was thinking the result of division is rounded down. In python 2 it is -3. Is there any other rule for division in java?
Jon Skeet
people
quotationmark

Is there any other rule for division in java? As always, for questions like this you should go to the Java Language Specification. In this case, the relevant section is 15.17.2: Integer division rounds toward 0. That is, the... more 10/4/2014 7:59:08 AM

people

How can I call the method from class Z3_2 in main class?

public class Z3_2_Tester{ public static void main(String[] args){ char[] tablica = {'S','O','M','E','T','E','X','T'}; Z3_2 z = new Z3_2(); ...
Jon Skeet
people
quotationmark

You've got three mistakes at the moment - one is not an error, it's just a really bad idea. The other ones are what you're running into at the moment. Firstly, you've got a static method, but you're calling it as if it were an instance... more 10/3/2014 8:50:05 PM

people

How can I add specific escape characters to xmlserializer?

I have a method that serializes an object to xml and returns the string: public static string SerializeType<T>(T item) { var serializer = new...
Jon Skeet
people
quotationmark

% isn't really a reserved character in XML. The documentation you've referred to is for SQL server, and there's a small note under the table: The Notification Services XML vocabulary reserves the percent sign (%) for denoting... more 10/3/2014 8:24:38 PM

people

How can I change Integer value when it is an argument like change array's value?

public static void main(String[] args) { Integer i = new Integer(0); int[] arr = {1}; p1(i); p2(arr); System.out.println(i); ...
Jon Skeet
people
quotationmark

You can't change the value of the variable i in main from within the p1 method, because the argument is passed by value: the parameter i in p1 is entirely separate from the i variable, it's just that they have the same value at the start... more 10/3/2014 7:32:02 PM

people