Thomas Thevis

Ranch Hand
+ Follow
since Sep 02, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Thomas Thevis

The statements are different! The first one could lead to a NullPointerException in the case that the map is not empty but the requested key not contained. In the case where there is a value for the provided key, the isEmpty() method is called for the contained list.
Your second statement simply checks whether the provided key is used in the map (alternatively, there is a method containsKey() for this kind of task).
15 years ago
Hello Edmen,

have a look at this posting from several weeks ago: quantifier.

Regards,
Thomas

[ October 23, 2008: Message edited by: Thomas Thevis ]
[ October 23, 2008: Message edited by: Thomas Thevis ]

My thoughts did wander in this direction but was trying to avoid this route since it is, like you mentioned, "kind of dirty". The code made things easier for me.

Thanks!


You're welcome
If you find a solution which is not as dirty, I'd be very interested in knowing about.

Regards,
Thomas
15 years ago
Hello Anoobkumar,

if you put 'final' in front of one of your instance variables, you have to assign a value yourself. You can do this at the same time you declare that variable or you can do this in your constructors. However, you have to ensure that after your constructor (regardless of which one) has run, the variable will have a value assigned. Otherwise, the compiler will complain.
If the compiler would set a default value at declaration time, you wouldn't be able to set a value in your constructors because of the 'final' modifier.

Regards,
Thomas
15 years ago
Hello Onkar,

I don't know whether I got your question right. If you want to format a date for a given locale you would perform the following steps:

But this is not your question, right? You want to retrieve the pattern that is used for formatting?
I think, there is a kind of dirty way to retrive the actual pattern. If you have a look at the runtime type of the DateFormat from above, this will usually be a SimpleDateFormat. And the SimpleDateFormat has a method toPattern(). Therefore, you can try to retrieve the pattern as follows:

In case your DateFormat instance is not a SimpleDateFormat you could create a fallback solution by defining some kind of dummy date, use the steps of the first code block to retrive a formatted instance and use this one to get the numbering order and separating characters.

Hope this helps,
Thomas
15 years ago
One thing I forgot to mention:
Although the Object's specification of equals() has been changed by the Comparator interface, the hashCode()'s specification has not. Therefore and as always, to not break the general contract of Object's hashCode(), you'll have to override hashCode() in case you decide to override equals().
Hey Parthiban,

the equlas() method is only to compare different instances of Comparator implementations. For sorting data, it definetly suffices to implement the compare() mathod. I use the Comparator quite often and have never implemented equals() so far. So, why is it there and why don't we have to implement it? Well firstly, as you can see, the method signature is the same as the one from java.lang.Object. Since each class you implement inherits from Object, there is always a valid implementation matching the one from the Comparator interface. So, why is it there at all? If you read the API doc for Comparators equals() method carefully, you'll find that the interface specifies additional bahavior diverging from the Object's equals() specification. Therefore, the method is listed there. You don't have to implement equals(), but if you do, you have to fulfill the specification from the Comparator interface.

Hope this helps,
Thomas
Hello Kiran,

try to use the search function of the forum first. You will come to threads like HAS-A relationship?.
If you don't find an answer to your question, come back afterwards.

Regards,
Thomas
15 years ago
I'm afraid you won't find many people doing the coding stuff for you. However, there will be many people 'round here assisting you in developing a solution. What have you tried so far?
There are third-party APIs for html parsing like org.htmlparser or jtidy. Have you tried them?
If you want/have to code the parsing yourself, you could have a look at the java.util.regex package.

Hope this helps,
Thomas
15 years ago
Hello Sruthi,

there were several people with similar problems in the last days. Try to search this forum for these threads first, as for instance Not able to run a class file. If all these threads do not help, come back here and post what you tried so far.

Someone will know how to help

Regards,
Thomas
15 years ago
Hey Bob,

good explanation. I think you're right.

Regards,
Thomas

Originalliy posted by Muhammad Ali:
For this I'd have to implement the sort method.


Actually not. Wirianto Djunaidi is quite right. Have a look at the java.util.Comparator interface. You don't have to implement sort(), but to provide a Comparator which performs a comparison on pairs of your bean objects. For each column to sort, you can provide a different Comparator.

Regards,
Thomas
15 years ago

Can I assume that, because I didn't override the hashCode() of Object class in Employee class, LinkedHashSet is allowing duplicates.


Well it depends on what you define as duplicates. Fot the HashSet both your Employee instances Vasu are completely different objects. If you don't want these objects to be treated differently you have to override the java.lang.Object's default equals() implementation (and don't forget to override hashCode() as well!).
[ October 15, 2008: Message edited by: Thomas Thevis ]

In case If I want to create readonly arraylist object what can i do ?
so that by using ar.add("abc"); will given an unmodifiable exception



java.util.Collections has methods for that kind of task. have a look at the API docs.
15 years ago
If java is properly installed on your system, it should suffice to only type 'java'. You can check this by typing 'java -version'. If you receive some information about your JVM you're fine. Otherwise, check whether your 'path/to/java' is actaually a path to the java binary. If so, it usually looks something like 'path_to_java_install_dir/bin/java'.
[ October 15, 2008: Message edited by: Thomas Thevis ]
15 years ago