Mike Jensen

Greenhorn
+ Follow
since Aug 27, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Mike Jensen

Try this:

String myString = "hellothisisastring";
if(Pattern.matches("[a-zA-Z]+", myString))
{
System.out.println("Yep!");
}
else
{
System.out.println("Nope!");
}
12 years ago
Unfortunately yes.

The type parameter in your List<Type> will be erased during compilation to just be a List.

This means that you cannot at runtime get hold of the type the List was declared to hold.

A couple of other interesting examples, if you have:

class MyClass<T>
{
T someVariable;
}

At compile time the type parameter <T> is erased and the usage of T in the variable declaration will be changed to Object.

class MyContainerClass<T extends Number>
{
T someVariable;
}

When this class is compiled the type parameter <T extends Number> is erased, and the usage of T is replace by Number.

12 years ago
I like to use the IntArrayList from Colt. (http://acs.lbl.gov/~hoschek/colt/)

Colt provides a set of Open Source Libraries for High Performance Scientific and Technical Computing in Java.

Api for the IntArrayList is: http://acs.lbl.gov/~hoschek/colt/api/cern/colt/list/IntArrayList.html

The IntArrayList can grow dynamically, you use it like this:

IntArrayList intList = new IntArrayList();

for (int i = 0; i < 10; i++)
{
intList.add(i);
}

intList.trimToSize();
int[] myIntArray = intList.elements();

The Colt library has more goodies than this, check it out

12 years ago