Pages

Showing posts sorted by relevance for query OutOfMemoryError. Sort by date Show all posts
Showing posts sorted by relevance for query OutOfMemoryError. Sort by date Show all posts

Wednesday, December 22, 2021

Java List or ArrayList Max Size (With Examples)

1. Overview

In this tutorial, We'll understand what is the limit of ArrayList or List implementations that can hold the maximum size.

But this is completely different from finding maximum value from ArrayList.

Before finding the max size of ArrayList, we need to understand that ArrayList collection API is implemented based on the ordinary arrays of java.

If the new ArrayList<Integer>(5) then a new ArrayList with the size of 5 is created and it can store 5 integer values.

Java List or ArrayList Max Size

Friday, November 1, 2019

How to Read a Large File Efficiently In Java

1. Overview


In this tutorial, You'll learn how to read the file fast in java efficient manner.

Before going to our topic, Every programming developer must be working on some technology such as java, python, c++ or swift. Either developing web applications or mobile applications. All the user operations must be saved in files, databases or in-memory or in image format. But here the challenging part is doing it considering the performance aspect. This is what you are going to see how to read the file in java efficiently.

And also this is a famous interview question for all level java developers. We will see the good and bad ways to read large files.

How to Read a Large File Efficiently In Java

Wednesday, January 15, 2020

Java WeakHashMap Working Examples

1. Overview


In this tutorial, We'll be talking about WeakHashMap in java and it is placed in java.util package.

WeakHashMap is implemented based on Hashtable with weak keys. Map internally is built on Entry objects. When adding a key-value pair, it will be stored in the Entry object. An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use. So, once the key is deleted from the map it is eligible for Garbage Collection and we can not prevent from running GC on it. This class completely behaves differently than other Map implementations such as HashMap, LinkedHashMap, etc. And also it has efficiency parameters of initial capacity and load factor as same as HashMap.

Java WeakHashMap Working Examples


AbstractMap is the superclass for WeakHashMap and it implements Map interface. So, it acquires all its default methods. WeakHashMap is designed to store null values as key and value.

We should understand the basic terms Strong reference, Soft Reference, and Weak Reference.

Next in this article, We will see example programs on each method of this class.

Friday, June 12, 2020

Java Program To Reverse A String Using Recursion

1. Introduction


In this article, You're going to learn how to reverse a string using recursion approach. The first program is to reverse a string and the second program will read the input from the user.

In the previous articles, I have shown already how to reverse a string without using any built-in function and also how to reverse the words in a string.

Java Program To Reverse A String Using Recursion

Friday, May 31, 2019

Java String API replace() Method Example

1. Java String replace() Overview


In tutorial, We'll learn about Java String replace() method and explanation with examples. replace() method is used to replace a character with another character in a String and this method returns a new string after replacing characters.

In previous tutorial, We've seen How to use Java 11 String API repeat() method.

Java String API replace() Method Example

1.1 Syntax


public String replace​(char oldChar, char newChar)
public String replace​(CharSequence target, CharSequence replacement)

replace() method is available in two variants. First variant takes two char's as input and replace a char by a new char. Where as in second variant, It takes two CharSequence as arguments and replace one CharSequence by new CharSequence.

Here, CharSequence means String, StringBuffer, StringBuilder. Any one of these can be passed as arguments to the second variant of replace().

Wednesday, May 29, 2019

Java 11 String API repeat​() Method Example

1. Java 11 String repeat​() Method Overview


In this tutorial, We'll learn about Java String API repeat​() Method with examples. repeat() method repeat​s the string given n number of times.

repeat() method works as it name suggests.

Java 11 String API repeat​() Method Example

1.1 Syntax

public String repeat​(int count)

This is a public method and can be accessed on string instance directly.

1.2 Parameters

count - number of times to repeat

If we pass count as 3 then string repeats 3 times.

Saturday, August 15, 2020

Java 8 and Infinite Streams - How To Create Infinite Streams

1. Overview

In this article, You'll learn how to create infinite streams and how to use them in java 8.

Use Stream.iterate() and Stream.generate() method to create infinite streams in java. These two are declared as static methods and these are called utility methods.

Before diving into the Infinite Stream concepts, Let us understand the few concepts such as Intermediate and Terminal operation from Stream API.

Java 8 and Infinite Streams - How To Create Infinite Streams

Monday, April 8, 2019

Autoboxing and Unboxing Conversion with Examples in Java

Autoboxing and Unboxing in Java

Java 1.5 version has introduced Autoboxing and Unboxing in Java.

Autoboxing Conversion :


Converting primitive types to corresponding reference wrapper types called as "Autoboxing" and this happens run time implicitly.




Autoboxing and Unboxing in Java


Following are Autoboxing conversion in Java allow.

1) boolean to type Boolean
2) byte to type Byte
3) short to type Short
4) char to type Character
5) int to type Integer
6) long to type Long
7) float to type Float
8)double to type Double
Boxing conversion may result in an OutOfMemoryError if new instances are created.