• Post Reply Bookmark Topic Watch Topic
  • New Topic

API sorting method to convert ABCDEF to BCDEFA ?  RSS feed

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi, I was wondering if anyone knows a sorting method somewhere in the API that would accept this array as an argument
and return a new array BCDEFA ?

I want to implement a kind of "data-wheel" .. the method I'm looking for should turn the wheel one iteration.

I know this could be done by copying values to a new array in different locations, but I was wondering if anyone knows a quick-n'-easy API method ?

It doesn't have to be a char[] it could be a String[] etc.

Thanks for any suggestions.

 
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

Check Collections class. You could search for that class and available methods in http://docs.oracle.com/javase/8/docs/api/
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no standard API, it's not something that's needed very often. If you Google "java array rotation" there are a number of implementations.
 
Master Rancher
Posts: 2045
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the Collections class is easiest, as Liutauras mentioned.

If you do not want to use collections, then what about writing
a method, say:



making use of the fact that
gives an integer in the range 0 to length?

Greetz,
Piet
 
Liutauras Vilda
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:There is no standard API
Well, there is, specifically "rotate" method of Collections class. There is a trick which is needed to do by using arrays as a list, but it is possible to achieve using standard api. It wouldn't work straight with arrays of primitives, so it would be necessary to use wrapper class for char values.
 
John Mulholland
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help guys ! :-)
 
Liutauras Vilda
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Mulholland wrote:Thanks for the help guys ! :-)

Did you come up with solution to your problem? Post it here, to see if we got the same.

You're welcome
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be a little late, but have you looked into using a circular linked list? once it is built, to 'rotate' it all you'd need to do is advance the head and tail pointers one node.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!