• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Java: How to divide a string into certain segments with different number of letters?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! I need to create a method that  returns reversing array of Strings. Also need to change their order in such way that their length stays the same as the length of the original inputs.

Example:

Input:  {"Don't", "worry", ",", "be", "happy", "!"}

Output: {"!yppa", "heb,y", "r", "ro", "wt'no", "D"}




This should be in the form of the String[] reverse(String[] a) method.

I have already created a method that reverses the String array(and converts it to a simple String). But I can't figure out how to divide this String into certain segments and insert them into array. Please help!

Here's my code:

 
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 how to divide this String into certain segments


If there is a String with the text, not an array of Strings, the String class's substring method will extract the desired segments.
 
Marshal
Posts: 72407
315
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Go through the String class, and StringBuilder; there are lots of methods you might not have thought about.
 
Grow your own food... or this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic