Browsing 7239 questions and answers with Jon Skeet

Is there any way to access a String variable inside of a for loop?

I need to access the two String variables suit and rank, then use them outside of the for loop. Is this at all possible? public class Deck { public static void...
Jon Skeet
people
quotationmark

If you're trying to deal a hand then it seems to me you need a collection - after all, a player holds multiple cards. I think you need to take a step back, rather than continuing with your current code. I'd do it something like... more 12/30/2013 8:54:41 AM

people

Error running SQL query on C# OleDbException was unhandled, characters found after end of SQL statement

Whenever I run the below event on C# I get the following error message - OleDbException was unhandled, characters found after end of SQL statement at the int affectedRows =...
Jon Skeet
people
quotationmark

I suspect you were actually trying to use parameters - note that your pgp and team variables in C# aren't being used at all in your code. I suspect you want something like: using (OleDbConnection conn = new OleDbConnection()) { string... more 12/29/2013 6:15:07 PM

people

Best way to 'remap' a simple binary mask?

I got a very simple binary mask. 1 = Sunday 2 = Saturday 4 = Friday 8 = Thursday 16 = Wednesday 32 = Tuesday 64 = Monday So if you want a...
Jon Skeet
people
quotationmark

You should use an enum: [Flags] public enum WeekDays { Sunday = 1, Saturday = 2, Friday = 4, Thursday = 8, Wednesday = 16, Tuesday = 32, Monday = 64 } A simple explicit conversion will do the "remapping"... more 12/29/2013 5:45:53 PM

people

Is it necessary to set obsolete references null when they will get reassigned?

Let me first premise my question with the fact that I am learning programming/data structures. Yes, I know that Java has a collections API to do what I am coding, but for the...
Jon Skeet
people
quotationmark

No, there's no need to do that. It won't make any difference to garbage collection. It's only important to set a variable to null (in terms of garbage collection) in one of these cases: It's a local variable in a long-running method It's... more 12/29/2013 8:51:17 AM

people

Why won't JButton.setBounds work in a for loop?

The setBounds methods works fine if it's not in a for loop but the moment I place it in a for lopp it seizes to work why is this? btnResize.addMouseListener(new MouseAdapter() { ...
Jon Skeet
people
quotationmark

You're doing this in the UI thread, which means nothing in the UI has a chance to react to it until the loop has finished... only the last setBounds call will really have any visible effect. If you're trying to perform animation, you'll... more 12/29/2013 8:45:11 AM

people

Error: Could not find or load main class concurrency.MainTest

I installed eclipse kepler and JDK 1.7.45 on lubuntu 13.04 Here is java version: nazar@nazar-desktop:~$ java -version java version "1.7.0_45" Java(TM) SE Runtime Environment...
Jon Skeet
people
quotationmark

You haven't really made it clear what you've done in Eclipse, but we can easily fix the "compiling and running it from the command line" problem. You're compiling and running it from the wrong directory. Compile it from the root, either... more 12/28/2013 11:03:02 PM

people

When is really alive a thread in java?

If thread is sleep or waitting, is it alive or not? What would return thread.isAlive() True ore False in these two cases?
Jon Skeet
people
quotationmark

It's still alive, just not running. From the documentation: Tests if this thread is alive. A thread is alive if it has been started and has not yet died. A thread which is just sleeping or waiting hasn't died (it hasn't exited its... more 12/28/2013 10:54:20 PM

people

Find and return matched string from List

I have a list of string and gridview rows where I need to find if row contains any of the string from my list and return the matched string. This is my list...
Jon Skeet
people
quotationmark

If you're looking for an exact match, you just need: bool found = lstRemovecol.Contains(row["Item code"].ToString()); No need for LINQ at all, or Any. If you're trying to find any of the items within a longer string (for example, if... more 12/28/2013 1:18:33 PM

people

Using statement on object passed via parameter

Seeking best inputs on correct usage of C# using statement. Can I use using statement on a parameter object as in the following uncommon example code snippet (viz., multi-layer...
Jon Skeet
people
quotationmark

Can I use using statement on a parameter object as in the following uncommon example code snippet (viz., multi-layer application)? You can, but it's generally odd to do so. Usually whatever is creating the StreamReader would be... more 12/28/2013 11:17:43 AM

people

how to write string with outputstream(Telnet client) using java

i tried to use this code but when i start the connection it seems that the server doesn't receive the string(the command): public static void sendMessage(TelnetClient s, String...
Jon Skeet
people
quotationmark

You definitely don't want to use ObjectOutputStream - that will use binary serialization that your telnet server won't be expecting. It would be best to create an OutputStreamWriter: // Adjust the encoding to whatever you want, but you... more 12/28/2013 10:00:19 AM

people