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 7009657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:53:25+00:00 2026-05-27T21:53:25+00:00

I have an array which contains objects some may be same and some are

  • 0

I have an array which contains objects some may be same and some are different.
How can I take each same objects and different objects separately ?

Below is the array

NSMutableArray *items = [[NSMutableArray alloc]
 initWithArray:[NSArray arrayWithObjects:@"rat", @"rat", @"cat",@"Lion", @"cat", @"dog", @"dog", nil]];

I want to have four arrays which will contains these items :

  • First array with two rats
  • 2nd array with two cats
  • 3rd array with one lion
  • 4th array with two dogs

What could be the best way to take the objects out ? Identical object should be placed in same array.

  • 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-27T21:53:26+00:00Added an answer on May 27, 2026 at 9:53 pm

    Here’s a general answer:

    Put the array into an NSCountedSet – that will store each object and a count of the number of times it has been added.

    Then – for each object in this counted set create an array with that object repeated according to the count of each object.

    It will work in your case, because you are using static strings, which are going to be the same if they are the same string. This will take more work if you are using custom objects.

    But the real question we have to ask is why you need to create these repetitive structures. If we could know what you are doing with it, we could give you better advice about how to go about it. For example, if you just need to keep a running count of the number of each type of object you have, you could just use the NSCountedSet directly (it descends from NSMutableSet, so it is already mutable) and not bother with creating the arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which contains around 50-200 hyperlinks. How can I pass this
I have an Array of Objects which I want to filter depending on some
I have an array of JSON objects, some of which contain key/value pairs for
I have an array which contains another array Would I notate it this way?
Am I missing something in the Array documentation? I have an array which contains
I have an array DetailsArray in VB.NET which contains the result of a LINQ
I have a plist which contains an array of NSDictionary 's which represent a
I have an array that contains a list of vertices which I copy to
In a PHP program I have an array of some custom objects, and I
I have a List of objects which contain a string array as one of

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.