Number of Characters in Java String

0 votes

I was working on a code where I am supposed to find the palindrome for an integer of up to a million digits. To make my task easy, I was thinking of using the String reverse function. But I have a doubt regarding the max length of the String that Java allows. Have anyone any idea regarding this?

Oct 22, 2018 in Java by 93.lynn
• 1,560 points
26 views

1 answer to this question.

0 votes

I think you can make use of either of the following to know the max length of String you can use:

  1. Integer.MAX_VALUE (always 2147483647 (231 - 1).​
  2. Half of your maximum heap size as each character is two bytes
answered Oct 22, 2018 by anto.trigg4
• 3,420 points

Related Questions In Java

0 votes
2 answers

What is the easiest way to iterate through the characters of a string in Java?

There are two approaches to this: for(int i ...READ MORE

answered Aug 19 in Java by Sirajul
• 25,180 points
59 views
0 votes
3 answers

How can I separate the digits of an int number in Java?

import java.util.*; public class AmstrongNumber { public static void ...READ MORE

answered Aug 6 in Java by anonymous
1,835 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,450 points
85 views
0 votes
2 answers

Get all the permutations of a string in Java

You could use recursion to do this.  Try ...READ MORE

answered Aug 21 in Java by Sirajul
• 25,180 points
89 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,050 points
663 views
0 votes
2 answers

Generate an alpha-numeric string randomly

Java supplies a way of doing this ...READ MORE

answered Jul 18, 2018 in Java by Daisy
• 8,050 points
184 views
0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,540 points
90 views
0 votes
2 answers

Counting no of Occurrence of a particular character inside a string in Java

We can find out the no. of ...READ MORE

answered Sep 7, 2018 in Java by Sushmita
• 6,880 points
246 views
0 votes
1 answer

Retrieve all the implementations of an interface in Java

Hi...I think you can achieve this by ...READ MORE

answered Jul 23, 2018 in Java by anto.trigg4
• 3,420 points
520 views
0 votes
1 answer

Setting time zone of a java.util.Date

You can make use of the following ...READ MORE

answered Aug 14, 2018 in Java by anto.trigg4
• 3,420 points
3,729 views