This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!

Tyoma Sakurakoji

Ranch Hand
+ Follow
since Dec 15, 2009
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 Tyoma Sakurakoji

wayne brandon wrote:trying to make characters in my input numbers only from index 4 to 20

is there a way i can do it here...or do i have to have an if for every index?

tried 1,2,3 didnt like it
tried 4-20 gives me an error


Or maybe you mean that letters letters containing numbers in your input string should be allowed only in postitions starting from 4 to 20? In that case you can write regular expresion checking is it true:
Means input string must start from 4 non digit letters, then having 16 digit letters and then any number of non digit letters...
1 week ago

wayne brandon wrote:trying to make characters in my input numbers only from index 4 to 20

is there a way i can do it here...or do i have to have an if for every index?

tried 1,2,3 didnt like it
tried 4-20 gives me an error


Are you trying to filter your input allowing only characters from the range of indexes of 4 to 20? Then what is the index mean in this context? Is it a character code?
1 week ago

Campbell Ritchie wrote:Actually, it is by no means difficult to implement a stack.


It is not as dificcult as it sounds. You can build stack on top of the list as a delegate, just by adding peek/pop/push methods...
1 week ago

Campbell Ritchie wrote:

Tim Holloway wrote:There is no iterator for a Map. . . .

Tim is correct; if you look at the Map interface, you won't find an iterator() method.


Oops, included it in quote accidently (
1 week ago

Tim Holloway wrote:

Campbell Ritchie wrote:

praveen kumaar wrote:. . . Their is no such thing like order for HashMap . . . .

I thought the resultant List was to be sorted backwards by the “V”s in the Map. That is different from encounter order.



Hashcodes are integers, so no "V". You're thinking of the default output of toString, which is actually based on heap internal storage location or something like that, I think.


I think Richie mean that the orignal problem that was given to TS was to filter all the languages from the map that has score >= 60 (score = majority of the language within the world) and then display them according to majority in decending order. It really sounds logical and I start to thought that it really was the original intention of the problem. That's why Ritchie was insisted on using value instead of the key. We all have been confused by the first post describing the task ))
1 week ago

Tim Holloway wrote:There is no iterator for a Map. Instead you have to get the keySet, entrySet or valueSet and iterate that. Sets iterate in no guaranteed order, and while you might assume that a HashSet might iterate its keys in ascending hashvalue order, there are no assurances, and even if there were, you'd have to consider whether overflows were handled depth-first or not.

In brief:

A) you cannot iterate a Map, only retrieve a Set of data (keys, values, or Entries) from the Map.
B) As Sets have no natural order, you should treat them just like database tables. If you want an order, you have to enforce an order.


This is true only for some implementation of the map (i.e. HashMap), but not in general.
Also values are returned from Map as Collection and not as Set since map can hold equal values.
1 week ago

Marcello Lippi wrote:Honestly, I would love to see solution for my initial code. Yes, it is extremely ugly, but at least I do understand it. In the same time, your solutions are brilliant, but I don't understand streams completely yet.


I just used variable name as inputMap in the sake of clarity, you should use the variable name that is passed inside the method
1 week ago

Jordan Cozart wrote:Pastebin
Pastebin
Pastebin
The links above take you to the three classes i have.


I need to write a class called Book that has 3 Attributes: title, author, and category. The class has a constructor, a getter for the category, and a toString method. The toString method should return a string that has the same format as this example: How To Finish Homework On Time by Will B. Dunn, category: nonFiction. After that i need to write a driver class that has 3 stacks: toBeSorted, fiction, and noFiction. The driver class should push all the books from the file books.txt onto the toBeSorted stack(which i have already done). The driver class should then iterate through the toBeSorted stack, display the book on top of the stack (Hint: This is where the toString method in the Book class comes in), and sort them by category. That means to  push each book onto the fiction or nonFiction stack, based on its category and then pop the book of the toBeSorted stack. At the end, the program should display the number of books on each stack, if the toBeSorted stack is empty, and which book is on top of each of the other stacks.


Well, you have all to start with. So what's the problem? Iterate through the first stack and categorize all the books.
BTW, is it requirement to implement your own stack?
1 week ago

Junilu Lacar wrote:It seems to me a concrete example is needed to clarify the requirements. Plain English descriptions can be inexact and ambiguous and open to individual interpretation.

What I understand is this:

Given a Map<String, Integer> {
 "English" -> 90,
 "Spanish" -> 70,
 "Bahasa" -> 50,
 "Japanese" -> 62,
 "Tamil" -> 5,
 "French" -> 73,
 "German" -> 79
}

The first step of filtering results in a String array containing everything except Bahasa and Tamil since these have values less than 60.
Next step is to sort them in descending order by value in the Map so:

["English", "German", "French", "Spanish", "Japanese"]

That is final result.

Is this the correct interpretation of the requirements?


I think the last step is not sorting, but reverse against encounter order, so the answer would be (asumming encounter order would be the same as it is written above):

["German", "French", "Japanese", "Spanish", "English"]
1 week ago

praveen kumaar wrote:

Tyoma Sakurakoji wrote:Are you need to preserve the original order of the input hashmap entries and just reverse it afterwards? If so, then remove sorted call and reverse the resulting list


Their is no such thing like order for HashMap as it is a unordered data structure, even HashSet is unordered and and streams also does not guarantee any ordering(Encounter order) for such objects. if you really want to preserve ordering LinkedHashMap preserves the same.


You right, I mean encounter order
1 week ago

Tyoma Sakurakoji wrote:In the original code also values were added in the list.


I mean keys
1 week ago

Campbell Ritchie wrote:

praveen kumaar wrote:. . . Their is no such thing like order for HashMap . . . .

I thought the resultant List was to be sorted backwards by the “V”s in the Map. That is different from encounter order.


Sorry, still can't get why you think values would be used? The code of the first post and the problem description was saying that it first needed to display only those languages that has score >= 60, then list of string should be reversed against its original order. The only String values here are keys. In the original code also values were added in the list.
1 week ago

Stephan van Hulst wrote:I missed that you likely responded in regards to Piet's code. My comments apply to so-called 'real code'. As Piet said, he is just experimenting.


Oops, sorry for misleading you. I'll use quote next time...

Marcello Lippi wrote: Hi all,
Then I should sort array list of strings in descending order comparing to its equivalent in hashmap


It seems I doesn't get the whole problem. Are you need to preserve the original order of the input hashmap entries and just reverse it afterwards? If so, then remove sorted call and reverse the resulting list:
1 week ago
Input map is Map<String, Integer>, code is filter using value and map using key. I think it's correct...
1 week ago