Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- Iterator



  Java SynchronizedList and Iterator

While reading some material about concurrency, I come up with some writing about using SynchronizedList wrap about normal List to enable synchronization.   But one interesting thing is http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#synchronizedList%28java.util.List%29   It says     It is imperative that the user manually synchronize on the returned list when iterating over it:     1   List list = Collections.synchronizedList(new A...

       2015-12-03 03:04:08

  Binary tree iterator algorithm

Binary tree pre-order,in-order and post-order traversal are basics in algorithm and data structure.And the recursive binary tree traversal is a classical application of recursion. We define a binary tree node as : // C++ struct Node { int value; Node *left; Node *right; } In order binary tree traversal can be: // C++ void inorder_traverse(Node *node) { if (NULL != node->left) { inorder_traverse(node->left); } do_something(node); if (NULL != node->righ...

   Binary tree,Iterator,Traversal     2013-07-14 21:51:09

  Difference between Enumeration and Iterator in java interview question and answer

This tutorial explains about what are the differences between Iterators and Enumeration and similarity of both interface which may be asked in a core java interview. Functionalities of both Iterator & Enumeration interfaces are similar that means both generates a series of all elements of the object which is to have its values iterated that can be traversed one at a time using next() method incase of Iterator and nextElement() method incase of Enumeration. The more powe...

   Java,Iterator,Enumeration     2012-05-01 07:41:52

  ConcurrentHashMap vs Collections.synchronizedMap()

ConcurrentHashMap and Collections.synchronizedMap() both provide thread-safe operations of collections of data. They are used in multithreaded programs to provide both thread safety and performance improvements. In many cases, we can use either of them. But the realization of thread safety is different for these two implementations. ConcurrentHashMap will create an HashEntry[] array internally to store the elements passed in from a Map, while Collections.synchronizedMap() will return a Synchroni...

   ConcurrentHashMap,Collections.synchronizedMap     2014-09-18 05:04:59

  Why exception would be thrown when deleting element while looping through HashMap in Java

HashMap and other Collection types are frequently used in Java application programming. This post will explain why exception would be thrown when deleting element with Map.remove() while looping through a Map using Iterator. This issue would also occur to other Collection types such as Set, List. Below is a sample code snippet demonstrating the exception thrown. Map<String,String> map = Collections.synchronizedMap(new TreeMap<String,String>()); map.put("key1","value1"); map.put("ke...

   JAVA,HASHMAP,CONCURRENTMODIFICATIONEXCEPTION     2018-06-30 12:49:09

  Is Scala Only for Computer Scientists?

I have experience struggling through these kinds of things andI know enough about the subject that I can understand why they did it that way. But my concern is that this should be an example that a beginner could understand, and they can't. There's too much depth exposed. Here's the example, which is written as a script: import scala.io.Source._ case class Registrant(line: String) { val data = line.split(",") val first = data(0) val last = data(1) val email = data(2) val payment = da...

   Scala,Application field,Computer science     2012-02-17 07:46:40

  3 ways to remove duplicates in List

Frequently, we may have an ArrayList which stores many values, and we need to process the ArrayList and get what are the distinct values in the list, or we may want to count occurrence of each value in the ArrayList. We can remove the duplicates in a few ways. Here we propose 3 methods :     public static void main(String[] args){        //SuperClass sub=new SubClass();                String[...

   Java,List,Duplicate,Clear     2012-09-03 09:44:32

  Canonicalize XML in Java

XML canonicalization is often used when there is need to create digital signature to be sent to peers for verification. Since digital signature is created based on XML data, the XML data has to be canonicalized before its signature value can be calculated. Even an extra space may affect the signature value calculated, hence it must follow some rules to canonicalize the XML data so that it has a standard format. This is why W3C created specification Canonical XML Version 1.1. This specificat...

   JAVA,XML,JAVA SECURITY     2016-01-20 01:39:45

  Top 10 essential Java classes

When we write Java programs, we will frequently use some classes such as java.lang.String. There are some essential Java classes which we may use frequently, there is no strict rules for the selection of essential Java classes, in fact there are no rules followed. It depends on what projects you are doing or what you have done,, so every one may have his own choices about the top essential Java classes in his mind. Here we list the top 10 essential Java classes you may agree with.1. java.lang.St...

   Java,class,essential class,top 10     2012-06-04 09:44:19

  Paradigms of Iteration in JavaScript

One of the joys of programming is that no matter how simple a problem may seem there are always tons of ways to solve it. It can be good practice to go back and revisit fundamentals by solving simple problems with as many implementations as you can think of. In this post we'll explore approaches to basic iteration in JavaScript. This style of exercise is a good interviewing technique, too, because it's open ended and leads to good discussions. The focus isn't a tricky, wacky problem you're...

   JavaScript,Iteration,Wrap,Recursive,For,Loop     2012-01-08 10:11:15