Browsing 7239 questions and answers with Jon Skeet

how to reinitialize a String[] with constants in java?

I have a switch case over several ints in java and in every case i want to redifine the String[] i set in the beginning of the method so i don't have to create several String[]...
Jon Skeet
people
quotationmark

You absolutely can reinitialize a string variable - but at the moment you're redeclaring it. Instead of: String[] locationProjection = { ... }; you want: locationProjection = new String[] { ... }; It's not entirely clear... more 5/27/2014 4:52:59 PM

people

private abstract classes in Java

I am a relative newcomer to Java. I recently came across a private static abstract class inside a regular class while browsing some Android app source code. What could be a use...
Jon Skeet
people
quotationmark

I've never come across this pattern before myself, but I can imagine it being useful if: You want to implement an interface in a similar way in a bunch of nested classes (e.g. to be returned from public methods within the enclosing... more 5/27/2014 6:24:36 AM

people

Is there a way to update GUI or use GUI while CPU is working?

The GUI of my program freezes while the program is doing its work. I created a mass import which can send X-thousand datarows via a called webservice into a database. The code is...
Jon Skeet
people
quotationmark

Firstly, you should rewrite it to use avoid synchronously doing this on the UI thread. If you do a lot of work on the UI thread, it simply will freeze the UI thread. There are a few options here: If your web service proxy supports... more 5/26/2014 7:14:33 AM

people

Same Java code returns different result running from Netbeans and JAR file

When i try to run java code using Netbeans, everything is good and RC2 encryption code gives 5B\q\OI5c¸ä3î1Ü. But running compiled jar file from windows the output is different...
Jon Skeet
people
quotationmark

It's almost certainly just the way the console handles non-ASCII characters in each case. However, that's a corollary to you doing something you shouldn't to start with: converting an arbitrary byte[] to String when you shouldn't do so, or... more 5/25/2014 7:28:34 AM

people

IO slow on Android?

This should show the internal and external memory speeds, but unfortunately it says it's 0.02 or 0.04 MB/s? Is this an enormous inefficiency in Android, or coding...
Jon Skeet
people
quotationmark

As well as the overhead Jonathon mentioned of opening and closing the file a lot, you're also calling write(int) for every single byte. Either use write(byte[]) with a big buffer, or use a BufferedOutputStream to wrap the... more 5/25/2014 7:17:03 AM

people

StringBuilder lost data when convert to String

here what's the problem I have problem when I tried to get String from my StringBuilder BufferedReader reader = new BufferedReader(new...
Jon Skeet
people
quotationmark

I'm pretty sure this is the problem: Log.i("===LoadDataActivity","rawdata: "+rawdata); You're assuming that a log entry can include all of your data - I believe each log entry is limited to 8192 characters. I suggest you log... more 5/24/2014 8:02:34 AM

people

Java ArrayList copy without creating a new array

I have a List implementation (not mine) with an underlying array. The implementation does not give access to the array directly, but only through the LIST INTERFACE methods that...
Jon Skeet
people
quotationmark

You're going to have to have a new array to back the ArrayList anyway - so why is it a problem that it calls c.toArray()? The only inefficiency would be if it ends up in the branch calling Arrays.copyOf. more 5/24/2014 7:56:51 AM

people

String to Date Java

I am trying to convert the string "5/23/14 02:23:24" from a String in Eclipse to a Date to insert into a SQL statement. The code I have is as follows: String dateAndTime =...
Jon Skeet
people
quotationmark

You're calling setDate, which uses a java.sql.Date. That represents just a date, not a date and time. You should consider using setTimestamp instead, with a java.sql.Timestamp. (There may be other ways of doing it for your specific... more 5/23/2014 4:31:08 PM

people

XDocument how can I comment an Element

I just want to know how I can comment an entire element using XDocument. XDocument doc = XDocument.Parse("<configuration> <connectionString> ... ...
Jon Skeet
people
quotationmark

Something like this, perhaps: var element = doc.Root.Element("connectionStrings"); element.ReplaceWith(new XComment(element.ToString())); Sample input/output: Before: <root> <foo>Should not be in a comment</foo> ... more 5/23/2014 3:39:14 PM

people

Is there a way to determine whether a parameter has this modifier?

I would like to determine if a parameter has this modifier using Reflection.I have looked at properties of ParameterInfo class, but couldn't find anything useful.I know the...
Jon Skeet
people
quotationmark

It's not exactly the same, but you can check whether the method has the ExtensionAttribute applied to it. var method = type.GetMethod("Square"); if (method.IsDefined(typeof(ExtensionAttribute), false)) { // Yup, it's an extension... more 5/23/2014 1:25:11 PM

people