Skip to content

Tag: java

Java enum elements with spaces?

Im working on java, I have created an enum as follows: Above example gives errors while using space in the name of element (i.e. north America). Any suggestions how to resolve above issue? Answer You can’t put a space in the middle of an identifier. Doing so ends that identifier and the parser assumes w…

How can I represent integer intervals in Java?

We all know about intervals in mathematics (e.g -4 < x < 3). How can I represent these mathematic intervals in Java, e.g, the numbers between -4 and 3 (-4, -3, …, 2, 3 etc)? Answer Check apache commons-lang IntRange. So, if you want to check if a number is in a given interval (range), you do:

Java Swing JtextField inset

I am working with Netbeans GUI and I would like to add 3 pixels of space at the beginning of my jTextField : I have tryied with setMargin, setInset in the GUI but it doesn’t change anything. I have another question, why the bottom right border is not rounded ? here is my code : thank you very much, Rega…

How to get maximum value from the Collection (for example ArrayList)?

There is an ArrayList which stores integer values. I need to find the maximum value in this list. E.g. suppose the arrayList stored values are : 10, 20, 30, 40, 50 and the max value would be 50. What is the efficient way to find the maximum value? @Edit : I just found one solution for which I am not

while EOF in JAVA?

Following to some forums answers I’m using this: … but it throws exception at the end anyway (Exception in thread “main” java.util.NoSuchElementException: No line found) Answer you should use while (fileReader.hasNextLine())

Create stylish charts in Java eg with JFreeChart

What’s the best way to create great looking charts in Java? It looks like the main option for charting is JFreeChart, but unfortunately by default they come out looking quite plain. Compare a sample of JFreeChart: http://www.jfree.org/jfreechart/images/PriceVolumeDemo1.png with one of the Javascript cha…