• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to remove duplicates from an array without changing order

 
Mohamed Riyaz
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Required solution to remove duplicate values from an array without changin order of the data.(Without usage of Collections,Set utilities)
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mohamed, and welcome to JavaRanch.
Since this sounds like a school assignment to me, I'll not give you a solution, but instead will try to point you in the right direction. You say you can't use Collections, but is there anything prohibiting you from creating a second array? Think about how you might use a second array to acheive this.
Once you figure out how to acheive this using two arrays, you might realize that this can be done using only the one array (albeit slightly less effeciently, especially if you have to shift the elements in the array whenever you remove an element).
Once you have some code ready, feel free to post if for critiquing/debugging. We'll gladly helpwith that part. (Be sure to surround your code with [ CODE ] and [ /CODE ] tags, as it makes it easier for us all here at the ranch to read.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic