JAVA

BitSet Class in Java

This class implements a vector of bits that grows as needed. Each component of the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative integers. Individual indexed bits can be examined, set, or cleared. One BitSet may be used to modify the contents of [...]

2018-01-25T22:48:57+05:30Categories: Programming|Tags: |

ArrayDeque in Java

An ArrayDeque is a special kind of a growable array that allows us to add or remove an element from both sides. It is an implementation of Deque Interface which allows insertion of elements at both the ends. It does not have any restrictions on capacity. It expands automatically as [...]

2018-12-14T19:24:25+05:30Categories: Programming|Tags: |

Generics | Java

Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively. Additionally, you don't have to cast the values you obtain from the collection. Example : List<String> strings = new [...]

2019-08-08T20:51:08+05:30Categories: Programming|Tags: |

Equals and Hash Code

Java super class java.lang.Object has two very important methods defined in it. They are - public boolean equals(Object obj) public int hashCode() public boolean equals(Object obj) This method checks if some other object passed to it as an argument is equal to the object on which this method is invoked. [...]

2018-12-14T23:04:57+05:30Categories: Programming|Tags: |

Difference between “==” and equals() method

The == (double equals) returns true, if the variable reference points to the same object in memory. This is called “shallow comparison”. The equals() method calls the user implemented equals() method, which compares the object attribute values. The equals() method provides “deep comparison” by checking if two objects are logically [...]

2018-01-21T21:33:47+05:30Categories: Programming|Tags: |

hashCode in Java

In Java, efficient hashing algorithms stand behind some of the most popular collections we have available – such as the HashMap and the HashSet. In this article, we’ll focus on how hashCode() works, how it plays into collections and how to implement it correctly. When using a hash table, these collections calculate [...]

2018-01-21T21:22:30+05:30Categories: Programming|Tags: |

Array of Arraylists in Java

Arrays of parameterized types are not allowed i.e. ArrayList<Integer>[] group = new ArrayList<Integer>()[4] Arrays of a ArrayList or any Java collection can be done as below ArrayList<ArrayList<Integer>> group = new ArrayList<ArrayList<Integer>>(4); Another way is if REALLY need array (bad design!): ArrayList[] group = new ArrayList[4]; ArrayList group[] = new ArrayList[4]; [...]

2018-12-14T20:05:53+05:30Categories: Programming|Tags: |

Inner Classes | Java

Inner classes are a security mechanism in Java. We know a class cannot be associated with the access modifier private, but if we have the class as a member of other class, then the inner class can be made private. Creating an inner class is quite simple. You just need [...]

2019-01-27T15:40:05+05:30Categories: Programming|Tags: |

Java : Read from file in Eclipse

To see where Java is looking for your file, put in your main method this statement: System.out.println(System.getProperty("user.dir")); Other way to add file in src directory as shown and add code Code is File file = new java.io.File("src/testCase.txt"); Scanner in = null; try { in = new Scanner(file); } catch (FileNotFoundException [...]

2018-01-14T20:27:19+05:30Categories: Programming|Tags: |

BigInteger in Java

BigInteger class is used for mathematical operation which involves very big integer calculations that are outside the limit of all available primitive data types. There is no theoretical limit on the upper bound of the range because memory is allocated dynamically but practically as memory is limited you can store [...]

2018-01-01T10:44:05+05:30Categories: Programming|Tags: |
Go to Top