/* create two Integer objects which are wrappers for integers */
Integer integer1 = new Integer(1);
Integer integer2 = new Integer(2);
/* create an ArrayList and add both objects to list1*/
Listlist1 = new ArrayList ();
list1.add(integer1);
list1.add(integer2);
// constructor tricks begin
/* to create a new list (list2) with elements of a list (list1)
* give list1 to the constructor of list2 while creating list2
*/
Listlist2 = new ArrayList (list1);
// you can see that their content are the same
System.out.println(list1);
System.out.println(list2);
/*
* we know that a large number of elements will be added to the list
* so the initial capacity of 10 will not be enough and
* the list will have to expand.
*
* if we have an idea about the potential initial size for a list
* we can ensure that the list's initial capacity will be large
* enough to handle the initial size of elements.
* */
final int potentialSize = 10000;
/* to create a list of desired capacity, give the capacity value
to its constructor */
Listlist3 = new ArrayList (potentialSize);
// add all elements to list3
for(int i=0 ; i < tmpinteger =" new">
Saturday, April 18, 2009
secrets of list class part 1: constructor tricks
List classes in Java can be thought as resizable arrays. They are very frequently used as they are handy. In this part of the article, I'll show you two constructor tricks that can become quite useful in special cases. The first trick is for using an existing list content for creating a new list. The second trick is for ensuring the element capacity of a list. You can ask yourself why are we giving a capacity value to a list if it can increase its capacity by itself. The answer is that yes, lists can increase their capacity by themselves but if we know the potential size we can skip waiting for the initial capacity adjustment and save some precious time. Here's the code for constructor tricks:
Saturday, April 11, 2009
10 things every programmer should know for their first job
James Stroup has a great article which can be quite useful for programmers who get their first job. I can't recommend it enough.
Thursday, April 2, 2009
bookmarking or launching several websites with a single click
There are lots of open websites and you want to check them later? Or there are several sites you want to open with a single click, so you don't have to open them one by one? Then, here comes maxthon 2's magical solution; using the groups.
Assume that there are several website tabs and you want to save them. You should
Next time you want to open all these previous sites, you should
Assume that there are several website tabs and you want to save them. You should
Open groups
Click on Add all tabs as group
Enter group name
Press OK :)
Next time you want to open all these previous sites, you should
Open groups
Click to the group name
Tuesday, March 31, 2009
suggested small language changes for jdk 7
Project Coin has the goal of grouping language changes suggested for JDK 7. David Linsin has brief listing of these proposals with code examples to clearify things. I suggest you to take a look.
Monday, March 30, 2009
how to fix sudo command in zenwalk 6
What you wait from sudo command is that it gives you the power of root for a single command. But you'll notice that it does not work properly in Zenwalk 6. To fix it;
check your group by opening your start menu > system > control panel > user profiles > list users > your_username > hit ok > note groupname value
open Terminal
type
su
and login (then you become root)
type
mousepad /etc/sudoers
edit the line after
# Uncomment to allow people in group wheel to run all commands
comment as
%your_groupname_value ALL=(ALL) ALLand save. Voila.
Subscribe to:
Posts (Atom)