> > Say I have array[100]; I want to assign each of them a Value of 0; In
> > just 1 step.
[quoted text clipped - 3 lines]
> Java gurantees the initialization with 0.
> Check the language specification.
What about char array?
char[] chararray = new char[100];
I want all of them to be ' '; Will they be done automatically? Can I
change the default parameter to something else?
> > SECOND
> > --------------
[quoted text clipped - 4 lines]
>
> You should catch the ArrayIndexOutOfBoundsException
Will it be as fast as checking just one condition without wasting much
time writing out the error? So that I can avoid Checking myself?
> > THIRD
> > --------
[quoted text clipped - 3 lines]
>
> No, you need to use a Set. They offer these methods.
How to initialize a set?
Currently I have two array
int[] array1 = new int[100];
int[] array2 = new int[100];
How to convert them to Set and use Set Theory.
How fast will they work When I use Union/ XOR/ etc. Will they be
performed in one step? And will the speed improve?
Bye
Sanny
Thomas Kellerer - 10 Jan 2008 10:49 GMT
Sanny, 10.01.2008 11:18:
>>> Say I have array[100]; I want to assign each of them a Value of 0; In
>>> just 1 step.
[quoted text clipped - 4 lines]
>
> What about char array?
Check the language specification it's all documented there:
<http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html>
>>> if (xx[i][j]=99;) === (Out of Bound) break; else proceed further. Can
>>> this be done in java?
>> You should catch the ArrayIndexOutOfBoundsException
>
> Will it be as fast as checking just one condition without wasting much
> time writing out the error? So that I can avoid Checking myself?
The bounds will always be checked by Java. There is no way to disable
this. Again read the language specs.
>>> Is it possible to use Arrays as Sets. And do Union, Intersect, and
>>> other things we do in Set Theory.
>> No, you need to use a Set. They offer these methods.
>
> How to initialize a set?
> Currently I have two array
>
> int[] array1 = new int[100];
> int[] array2 = new int[100];
>
> How to convert them to Set and use Set Theory.
Check the Javadocs for the different implementations of Set.
Basically it's: Set<Integer> set1 = new HashSet<Integer>(100) but that
will not add any entries to the set. As I said: you have to read the docs.
> How fast will they work When I use Union/ XOR/ etc. Will they be
> performed in one step? And will the speed improve?
Definitely not "in one step". I have no idea if your speed will
"improve". Firstly because I have no idea what your current code does,
and secondly because I have no idea what you new code will do).
You will need to test that for yourself.
If we are talking about 100 items per set, I wouldn't be concerned about
the speed.
Thomas
Lars Enderin - 10 Jan 2008 11:00 GMT
Sanny skrev:
>>> Say I have array[100]; I want to assign each of them a Value of 0; In
>>> just 1 step.
[quoted text clipped - 9 lines]
> I want all of them to be ' '; Will they be done automatically? Can I
> change the default parameter to something else?
See Arrays.fill(char[] a, char val):
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#fill(char[],%20char)
Lew - 10 Jan 2008 13:53 GMT
> Sanny skrev:
>>>> Say I have array[100]; I want to assign each of them a Value of 0; In
[quoted text clipped - 13 lines]
> See Arrays.fill(char[] a, char val):
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#fill(char[],%20char)
To the OP: this is a convenience method - it isn't "one step" at the low
level, but it is "one step" in your application code.

Signature
Lew
Lew - 10 Jan 2008 14:12 GMT
> Sanny skrev:
>>>> Say I have array[100]; I want to assign each of them a Value of 0; In
[quoted text clipped - 13 lines]
> See Arrays.fill(char[] a, char val):
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#fill(char[],%20char)
Arrays also has asList()
<http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#asList(T...)>
method, which can be combined with a Set's collection-arg constructor to
create the equivalent Set.
This example uses Character instead of char to obtain object-ness. When
building a Character array, avoid autoboxing from primitive [] inside a method
argument. That's why the Character [] is built prior to the Arrays.asList() call.
Character [] kars = { '0', 'Z', '-' };
Set <Character> karacters =
new HashSet <Character> ( Arrays.asList( kars ));

Signature
Lew