Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4578394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:28:43+00:00 2026-05-21T20:28:43+00:00

I have java String of say length 10 .Now i want to reduce it

  • 0

I have java String of say length 10 .Now i want to reduce it to lenthg of 5 .Is there something i can do like we do in C as shown below

 str[6] = '\0' ; //insert null at 6th place so remaining string is ignored.

I dont want to use inbuilt API of java to do this.The main problem that i wanted to solve is i wanted to remove duplicate characters in string .Now after removing duplicate characters string size is reduced so i want to remove remaining 5 characters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:28:43+00:00Added an answer on May 21, 2026 at 8:28 pm

    Strings in Java are immutable, as such you cannot modify the string but have to create a new one. As you cannot get your fingers on the underlying char[] of the String either, the only way to achieve your goal is using the API methods:

    String s = "blah blah blah";
    s = s.substring(0, 5);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java String with SGML, something like this... <misspell></misspell><plain>I</plain> <plain>know</plain> <plain>you</plain> <suggestion>ducky</suggestion>
Say I have a Java String which has xml data like so: String content
I have several java objects with four string properties as below: For e.g. say
In Java I have an arbitrary HTML document as a string. For simplicity, say:
I have a Java HashMap with Float keys and String values. now given a
I have some Java code which looks roughly like this: String urlString = ftp://polar.ncep.noaa.gov/pub/history/waves/multi_1.glo_30m.dp.200601.grb2;
I have some java classes like, Class User { String email; String name; String
In Java I have a defined a string named year: String year=year(now())-1 Now I
let's say I have this string array in java String[] test = {"hahaha lol",
I have a java string, which has a variable length. I need to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.