main
difference between Java strings and C, C++ strings?
In
C and C++, strings are terminated with null character. But in java,
strings are not terminated with null character. Strings are treated
as objects in java.
Using
Iterator, we can traverse the elements only in forward direction.
But, using ListIterator you can traverse the elements in both the
directions.
Using
Iterator, you can traverse List, Set and Queue type of objects. But
using ListIterator, you can traverse only List objects.
ListIterator Methods :
boolean
hasNext() –> Checks whether the list has more
elements when traversing the list in forward direction.
boolean
hasPrevious() –> Checks whether list has
more elements when traversing the list in backward direction.
HashSet
does not allow duplicate elements. If you try to
insert a duplicate element, older element will be overwritten.
HashSet
doesn’t maintain any order. The order of the elements will be
largely unpredictable. And it also doesn’t guarantee that order
will remain constant over time. If you want your elements to be
ordered in some way, you can use LinkedHashSet or
TreeSet.
The
BitSet
The
BitSet class implements a group of bits or flags that can be set and
cleared individually.
import
java.util.BitSet;
public
class BitSetDemo{
public
static void main(String
args[]){
BitSet
bits1
=new
BitSet(16);
BitSet
bits2
=new
BitSet(16);
//
set some bits
for(int
i=0;
i<16;
i++){
if((i%2)==0)
bits1.set(i);
if((i%5)!=0)
bits2.set(i);
}
System.out.println("Initial
pattern in bits1: ");
System.out.println(bits1);
System.out.println("\nInitial
pattern in bits2: ");
System.out.println(bits2);
//
AND bits
bits2.and(bits1);
System.out.println("\nbits2
AND bits1: ");
System.out.println(bits2);
volatile
: volatile modifier is used in multi threaded programming. If you
declare a field as volatile it will be signal to the threads
that it’s value must be read from the main memory rather then their
own stack. Because volatile field is common to all threads and it
will be updated frequently by multiple threads.
transient
: This modifier is used in serialization process. A variable which is
declared as transient will not be serialized during object
serialization.
No comments:
Post a Comment