fred rosenberger wrote:Not if you are inserting in the first position.
Ernest Friedman-Hill wrote:
Cheryl Scodario wrote:
Ernest Friedman-Hill wrote:
Removing from a linked list does, indeed, always take constant time.
Hi Ernest, why removing from a linked list always takes constant time? Because I kinda agree with Jesper that it will have to find the element to remove first, then actually do the remove action.
Finding an object takes linear time; subsequently removing it takes constant time. For an array, finding takes linear time for unsorted, and logarithmic time for a sorted list; and removing takes linear time.
Removing does not always imply finding. For example, consider removing the first element of a list. For a linked list, it's done in constant time, and for an array or ArrayList, it takes linear time.
Ernest Friedman-Hill wrote:
Removing from a linked list does, indeed, always take constant time.
Jason Koonce wrote:;
Now, below that is a bunch of methods, class summaries and things like that. Basically, what this is, is a small description in semi-plain English about what the class does. In this case it takes byte code and translates it to characters for other readers to make use of. In other words, a serialized non-text file that was stored as byte-code.
Jason Koonce wrote:One way of looking at the differences is in steps. With FileReader you read what? Just the characters, right? so what do you read should you have something other than simple characters? What if you tried storing multiple lines, serialized objects, or arrays? The stored information would simply read as a sentence for the FileReader.
BufferedReader, on the other hand, is more diverse in its capabilities. Using the information it receives from the FileReader it translates that information into meaningful code as well as Strings, should there be any, for you to then convert and manipulate in your program without adding a lot of additional, already been done for you, code.
Rob Spoor wrote:Let's make the code a bit more readable by splitting up that one statement, shall we?
Now, let's take "Hello" and walk through it.
i = 0: c is the int value of "H" which is 72 (see http://www.asciitable.com/). temp1 is 72. x is 72 % modulus.
i = 1: c is the int value of "e" which is 101. Assuming modulus > 72, temp1 is (101 + 256 * 72 == 18533. x is 18533 % modulus.
etc.
Campbell Ritchie wrote:There should be lots in the Java™ Tutorials; look for the "buffered" subsection.
fred rosenberger wrote:
So why we need FileReader? What is its function? Why can't we just have: ... = new BufferedReader("personDataBase")?
When you bake a cake, do the directions say "plant some grain, wait 6 months, harvest it, grind the seeds into a white powder. You will need two cups of that powder" or does it say "get two cups of flour"?
The idea here is that each of these objects do a little something, and you build off what others have done. And sometimes, you may what whole wheat flour, sometimes cake flower, sometimes all purpose flour...there may be times when you would want to pass something other than a FileReader into a BufferedReader.
marc weber wrote:When you start...
Index i holds element i Index j holds element j
In the "wrong" code, you have...
After this line runs...
Index i holds element j Index j holds element j
...so element i is lost (and the next line of code makes no difference).
The correct code avoids losing element i by storing it in a temporary variable.
Darryl Burke wrote:
// Pattern.java
public String[] split(CharSequence input, int limit) {
:
: // for certain conditions
return new String[] {input.toString()};
:
: // for other conditions
String[] result = new String[resultSize];
return matchList.subList(0, resultSize).toArray(result);
}[/code]So you see an array is always created in the same way, although that may not be in your own code.