Is there a way to determine if the loop is iterating for the last time. My code looks something like this:
int[] array = {1, 2, 3...};
StringBuilder builder = new StringBuilder();
for(int i : array)
{
builder.append("" + i);
if(!lastiteration)
builder.append(",");
}
Now the thing is I don't want to append the comma in...
I need to be able to store a date (year/month/day) with no time component. It's an abstract concept of a date, such as a birthday - I need to represent a date in the year and not a particular instant in time.
I am using Java to parse the date from some input text, and need to store in a MySQL database. No matter what timezone the databa...
I have an input String say "Please go to http://stackoverflow.com". The url part of the String is detected and an anchor <a href=""></a> is automatically added by many browser/IDE/applications. So it becomes "Please go to <a href='http://stackoverflow.com'>http://stackoverflow.com</a>".
I need to do the same using Java.
Thanks
...
I understand that BigDecimal is recommended best practice for representing monetary values in Java. What do you use? Is there a better library that you prefer to use instead?
...
I have a file (called "number.txt") which I want to read to an array in Java. How exactly do I go ahead and do this? It is a straight-forward "1-dimensional" file, containing 100 numbers.
The problem is that I get an exception every time. Apparently it can't find it (I am sure its spelled correctly). When looking through code examples, ...
So, let's say I want to write a class that operates on different kinds of numbers, but I don't a priori know what kind of numbers (i.e. ints, doubles, etc.) I will be operating on.
I would like to use generics to create a general class for this scenario. Something like:
Adder<Double> adder = new Adder<Double>();
adder.add(10.0d, 10....
Eclipse always warn me about serialVersionUID. What is this and is this a matter of high importance? Is there any example where missing serialVersionUID will cause a problem?
...
With Java Version 1.5.0_06 on both Windows and Ubuntu Linux :
Whenever I add minutes to the date "2008/10/05 00:00:00" , it seems that an extra hour is wrongly added.
ie: adding 360 minutes to 2008/10/05 00:00:00 at midnight should arrive at 2008/10/05 06:00:00
But it is arriving at 2008/10/05 07:00:00
The totally perplexing thing is...
Using Java, how can I test that a URL is contactable, and returns a valid response?
http://stackoverflow.com/about
...
private void activateRecords(long[] stuff) {
...
api.activateRecords(Arrays.asList(specIdsToActivate));
}
Shouldn't this call to Arrays.asList return a list of Longs? Instead it is returning a List<long[]>
public static <T> List<T> asList(T... a)
The method signature is consistent with the results, the varargs throws th...
Does anybody have a snippet of Java that can return the newest file in a directory (or knowledge of a library that simplifies this sort of thing)?
...
The equals()-method of the URL-class in the Java-class-library makes a DNS-request to get the IP for the hostname, to check the two IP's for equality. This happens even for URL's, that are created from the same String. Is there a way to avoid this internet-access?
...
Have you found Guice useful to manage DI in you applications or run stress tests or even brought an application using Guice to a production phase in your company?
If you have, have you run into any issues with it?
...
I need to configure Tomcat memory settings as part of a larger installation, so manually configuring tomcat with the configuration app after the fact is out of the question. I thought I could just throw the JVM memory settings into the JAVA_OPTS environment variable, but I'm testing that with jconsole to see if it works and it... doesn't...
If I have a key set of 1000, what is a suitable size for my Hash table, and how is that determined?
...
example:
I want to see if array[5] holds a value or is empty.
...
I am making a small game number game in Java (Nim) in OS X and was thinking about trying to make the GUI interface of the game using something other than Swing. I looked at SWT, but I read somewhere that SWT has some problems with OS X. I also looked at GTK+ bindings for Java, but I am not sure if that's a good choice either. Do you guys...
I'm trying to compile and run a sample bonjour program apple provides in the BonjourSDK found here:
http://developer.apple.com/networking/bonjour/index.html
The program is called SimpleChat.java. However, whenever I attempt to compile the program I get this error:
"SimpleChat.java:55: package com.apple.dnssd does not exist"
I can't for...
Hello,
I have been working on web application which includes java applet. My app is working fine on PC with different browsers like IE and Firefox. The web application hosted on Linux (Ubuntu).
I had problem on Mac with Firefox. I was unable to load the applet.
This is the error i found in java console.
Java.lang.classNotFoundException...
We have a application that should always be running. Does anyone know of a way to create an automated way of monitoring to see if this application is running (possibly using a batch file)? If it is not running, then send an email notification and start the application?
...