find duplicate words in java array and return array with unique duplicate words - use method, java: delete elements from arraylist while using iterator, Count occurrence of word in ArrayList of String, How to efficiently count the number of keys/properties of an object in JavaScript. In this article, we would like to show you how to count duplicated elements in ArrayList in Java. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, I wonder how much less traffic SO would get if the Java compiler were to warn on. java by Smiling Sable on May 13 2020 Comment . 3. Thanks for contributing an answer to Stack Overflow! The count() method is a built-in function that takes an element as its only argument and returns the number of times that element appears in the list. How do I read / convert an InputStream into a String in Java? */ public class Main { /** Count occurrences of character in string buffer. how to count the number of occurrences of an element in a arraylist in java. count occurence of element in arraylist. To count occurrences of elements of ArrayList, we create HashSet and add all the elements of ArrayList. You would probably something like that: Since you are looking for both the elements as well as the size, I would recommend Guava's Iterables.filter method, But as everyone else has pointed out, the reason your code is not working is the ==. Find centralized, trusted content and collaborate around the technologies you use most. WebIt is the simplest approach to count the occurrence of each character. For String you should use equals method. 1. What documentation do I need? How to update a value, given a key in a hashmap? operator is something people should be aware of because it's widely used. Stack Overflow for Teams is moving to its own domain! Stack Overflow for Teams is moving to its own domain! There already is an existing method for this: In your case, use like this (replace all of your posted code with this): You should compare strings using equals instead of ==. count in arraylist java. That's the table with results of every solution in the post (except those use Regex because it throws exceptions while parsing, how to make mickey mouse ears out of paper, does inheritance affect social security disability, fourier transform examples and solutions pdf, omega seamaster 300m bracelet or rubber strap, is it ok to wear white floral to a wedding, if an issue arises while you are ringing up a patient you should contact, negative ovulation test but still got pregnant, signs my wife is not sexually attracted to me, how to tune an electric guitar with a tuner, why do i start liking someone when they stop liking me, harry potter fanfiction harry cooks for tonks. ArrayList listName = new ArrayList<>(); 2. int occurrences On each iteration check each number against the media, and accordingly add 1 to above/below. The ArrayList class is a resizable array, which can be found in the java.util package. This is useful for validity checks. list<> java count. The same is true for any other number that repeats. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Alternative instructions for LEGO set 7784 Batmobile? The difference between a built-in array and an ArrayList in Java, is that the I have a bent Aluminium rim on my Merida MTB, is it too bad to be repaired? By using dirask, you confirm that you have read and understood, Java - convert comma separated String to ArrayList, Java - count distinct values in ArrayList, Java - count element occurrences in ArrayList, Java - iterate through Arraylist using iterator, Java - remove items from ArrayList using Iterator, Java - remove last element from ArrayList, Java - round ArrayList elements to two decimal places, Java - sort ArrayList based on Object field, Java - count duplicated elements in ArrayList. Write a Java Program to Count Array Duplicates with an example or how to write a program to find and count the duplicates in a given array. In this example, we count the number of duplicated elements in letters ArrayList using Collections.frequency() method. On the first iteration it prints "5 occurs 2 times", which is correct, but when we get to the fourth iteration, the number 5, it also prints "5 occurs 2 times". rev2022.11.22.43050. WebNumber of occurrences of ch in sb. how to count the number of occurrences of an element in a arraylist in java. count number of occurrences in arraylist java Code Answers. First the test: To solve your specific problem, you would create a counter, and iterate over your list, counting each element. How to find vector in the subspace that is the closest to y in mathematica. How to get the same protection shopping with credit card, without using a credit card? How do I count the occurrences of a list item? ArrayList listName = new ArrayList<>(); 2. int occurrences = Collections.frequency(listName, "element"); how to count the number of occurrences of get number of occurrences in list java. This removes redundancy and makes the code more readable, more reusable and more general. I like a two-pass approach better - in the first pass, simply put zero into the map; in the second, add one to the value. ok, thanks! Why writing by hand is still the best way to retain information, The Windows Phone SE site has been archived, 2022 Community Moderator Election Results. The ArrayList class has many useful methods. For example, to add elements to the ArrayList, use the add () method: To access an element in the ArrayList, use the get () method and refer to the index number: Remember: Array indexes start with 0: [0] is the first element. Connect and share knowledge within a single location that is structured and easy to search. We use Collections.frequency (Collection c, Object o) to count the occurrence of object o in the collection c. Below program illustrate the working of HashSet: Program to find occurrence of words Java import java.util.HashMap;. Is money being spent globally being reduced by going cashless? When the migration is complete, you will access your Teams at stackoverflowteams.com, and they will no longer appear in the left sidebar on stackoverflow.com. Is "content" an adjective in "those content"? Can an invisible stalker circumvent anti-divination magic? Quick solution: xxxxxxxxxx. Java - How do i make. package traversal; import java.util.ArrayList; import java.util.List; public class Occurrance { static int count; public static void main(String[] args) { List ls = It first takes the first element and finds the count and stores this in the first index of the output array. Welcome. The best way I can think of to count occurrences of things in an array with Java is with a Map. how to count the number of occurrences of an element in a arraylist in java . how to count the occurence in arraylist. static final int MAX_CHAR = 256; static void getOccuringChar (String str) {. Find centralized, trusted content and collaborate around the technologies you use most. But you're right, if it would have gotten more complicated than that, better use either a two-pass solution or use a proper if/else, depends on the requirements. count the number of occurrences of the same in a list java. We will use the second overload as we have to check the entire string. We use Collections.frequency (Collection c, Object o) to Write a Java program to count occurrence of an element in an array using for loop. This Java program accepts the size, array of elements, and the item to search for. The for loop iterate each item in an array, and the if statement compares that item with the number. if they both match, the occurrence variable increment by one. 1. int occurrences = Collections.frequency(myArrayList, element); Not the answer you're looking for? WebCreated by: Evie-Grace-Noble. It uses IndexOf and a while-loop. this is good if you want and know the exact word you want the frequency of, but repeating this for each word in the list @Yanick, yes but you can convert List to Set to know all unique words, ok, I've edited my post and added the conversion. Wave functions, Ket vectors and Dirac equation: why can't I use ket formulation on Dirac equation? WebWrite a Java program to count occurrence of an element in an array using for loop. When to use LinkedList over ArrayList in Java? public class CounterTest extends TestCase Does emacs have compiled/interpreted mode? CountOccuranceOfChar1.java. I.e. Webint count = myList.stream ().reduce (0, (soFar, current) -> soFar + (current == myElement ? Method 3 (Best using Improved Binary Search) 1) Use Binary search to get index of the first occurrence of x in arr []. //creating an array of size 256 (ASCII_SIZE) int count [] = new int[MAX_CHAR]; Traverse the list and increase the corresponding value in the map for it. How do I make my string comparison case insensitive? In case there is no entry yet, add one with the value 1. Connect and share knowledge within a single location that is structured and easy to search. Join to our subscribers to be up to date with content, news and offers. What is the difference between Voltage and Voltage Drop? Initialization of an ArrayList in one line, Converting 'ArrayList to 'String[]' in Java. how to count the number of occurrences of an element in a arraylist in java . java by Smiling Sable on May 13 2020 Comment. count occurrences in list of java. I have an ArrayList of words with duplicate entries. Thanks! == compares references, while .equals compares actual content of strings. int occurrences = Collections.frequency(listName, "element"); how to count the @Iola: yes, it's a static method, that's how you use it. It helps with checking that only one tag string is found in your HTML. If you think, the things we do are good, donate us. In this 3 different ways of counting elements of ArrayList are shown: Collections.frequency (arrayList, "A3"); using streams. I have a list of strings , I browse it and count number of "x" strings as below but the count doesn't print me the expected value: this gives [] it should be 2 as I have 2 occurrences of "x". How do I make my string comparison case-insensitive? While an hashtable solution is O(2n) at most, Already fixed it, but thanks for the hint ;). This avoids the sometimes confusing conditional logic, at (possibly) some slight performance cost. Also, when a new type is added, the generic class can be reused without writing additional. A fast to implement solution could be to use a Map where the String is each individual word and Integer the count of each. Input and output Input strings: Sam's first name is Sam. WebJava ArrayList. Or create a HashMap iterate over the arraylist and increase the count by one each time you see the string. I wish to travel from UK to France with a minor who is not one of my family. Not the answer you're looking for? @smas: That approach is both memory intense and inefficient at once. In this Java count duplicate array number example, we used a while loop to iterate Dup_Count_arrr array, count duplicate items (item shown more than once), and print the total. ok, I 've changed to equals, the problem now is that print me [1,2] instead of[2] ? public static void main(String[] args) {. import java.util.HashMap; public class Counter { private final HashMap map = new HashMap(); public int get(T key) { final Similarly, the count is. How are 'scraped content' websites like diningandcooking.com able to rank so well despite having no original content? java by Smiling Sableon May 13 2020 Comment. Our content is created by volunteers - like Wikipedia. Sorting Strings and extracting common elements of two String arrays in Java, Fastest way to determine if an integer's square root is an integer. In this blog you will learn how to count the number of occurrences of a character or word in a string in SQL Server .. How to count the number of elements in an array below/above a given number (javascript) Use Array#reduce with an object { above: 0, below: 0 } as initial value. In this program, we will create an ArrayList of Integers and add elements in it using add () method, then we will replace all occurrences of 21 with 200 using replaceAll () method. Parameters: This method takes the following argument as a Parameter list: the list in which replacement is to occur. How to find the number of times a particular value occured in arraylist in android? find total count of a string in list java. professorDAO.save (newProfessor); Professor oldProfessor = professorDAO.get (100); As you have seen, we can write one generic class that works with different types. java code to count the number of occurrences of highest numberan element in a list in java. What is a quick way to write "dagger" sign in MS Word equation mode? Old Whirpool gas stove mystically stops making spark when I put the cover on, Bach BWV 812 Allemande: Fingering for this semiquaver passage over held note, Profit Maximization LP and Incentives Scenarios. int [] arr = new int [] {1, 1, 7, 3, 2, 2, 2, 4, 1};. Space Complexity: O (logn), due to recursive stack space. WebTo count occurrences of elements of ArrayList, we create HashSet and add all the elements of ArrayList. Web$ cc odd_elements_occurrence.c $ ./a.out Enter number of elements: 5 Input 5 values: 23 41 22 14 57 Odd Element count in array: 3 Occurrence of odd element index's in array: 0 1 4 Previous Next C Program Examples. Why can't the radius of an Icosphere be set depending on position with geometry nodes. Alternative instructions for LEGO set 7784 Batmobile? Quick solution: int occurrences = this look even better, Count occurrences of words in ArrayList [duplicate], How to count the number of occurrences of an element in a List, Why writing by hand is still the best way to retain information, The Windows Phone SE site has been archived, 2022 Community Moderator Election Results, How to get the number of repeated values(count) from list, sort list with C# by how often same strings appear in list, count amount of unique words in a text file? Making statements based on opinion; back them up with references or personal experience. To count the occurrences of each element in an array: Declare a variable that stores an empty object. What does the angular momentum vector really represent? When to use LinkedList over ArrayList in Java? Rogue Holding Bonus Action to disengage once attacked, Interactively create route that snaps to route layer in QGIS, Cauchy boundary conditions and Greens functions with Fourier transform, Characterization of simple groups in terms of its conjugacy classes. I don't knwo why you're using a ArrayList to count. In this article, we would like to show you how to count duplicated elements in ArrayList in Java. To get the occurrences of the object from the list directly: To get the occurrence of the Object collection inside list, override the equals method in the Object class as: Call the Collections.frequency as: What you want is a Bag - which is like a set but also counts the number of occurances. The complexity of the count() function is O(n), where n is the number of factors present in the list. Use the forof loop to iterate over the array. i need array list, as getValue returns me an Arraylist, Count occurrences of a given string in an ArrayList, https://stackoverflow.com/questions/5116595/compare-two-strings-java. When the migration is complete, you will access your Teams at stackoverflowteams.com, and they will no longer appear in the left sidebar on stackoverflow.com. how to get chase card number before it arrives, kate aspen pink and gold will you be my bridesmaid kit, I wanted to know if there's a native method, how to call back a private number on android, I've made some research and found that Richard Watson's solution is fastest in most cases. I want to count and save occurrences for each word in a data structure. Site design / logo 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Why is processing a sorted array faster than processing an unsorted array? 411. Time Complexity : O (Log n + count) where count is number of occurrences. What numerical methods are used in circuit simulation? Webpublic int countNumberEqual(ArrayList itemList, Item itemToCheck) { int count = 0; for (Item i : itemList) { if (i.equals(itemToCheck)) { count++; } } return count; } Keep in On each iteration,. The code below uses count() to get the number of occurrences for a word in a list:. Had Bilbo with Thorin & Co. camped before the rainy night or hadn't they? If you don't have a huge list of strings the shortest way to implement it is by using Collections.frequency method, like this: List list ArrayList<String> listName = new ArrayList<>(); int occurrences = Collections.frequency(listName, "element"); Level up your programming skills with exercises across 52 languages, and insightful discussion with our dedicated team of welcoming mentors. Can an invisible stalker circumvent anti-divination magic? WebIn this article, we would like to show you how to count the number of element occurrences in Arraylist in Java. Site design / logo 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. 2) Use Binary search to get index of the How would the water cycle work on a planet with barely any atmosphere? Melek, Izzet Paragon - how does the copy ability work? Answers related to how to count the number of occurrences of an element in a arraylist in java count the number of occurrences of a character in a string java @smas, finding a word frequency = O(n), converting a List into a Set = O(n), looking for each word's frequency from the Set (worst case) = O(n); that's sums up to O(2(n^2)). In this program, we will create an ArrayList of Integers and add elements in it using add() method, then we will replace all occurrences of 21 with 200 using How do I convert a String to an int in Java? Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. How can I compare String value with ArrayList of String type in Java? 6. xxxxxxxxxx. raggedright and begin{flushleft} having different behaviour. Copy //package com.java2s; /* Please see the license information at the end of this file. Strings don't seem to be equal in Java on Android, even though they print the same. Sort it, iterate over it. WebThe np.char.count function counts the number of occurrences of the substring in the elements present in the string. rev2022.11.22.43050. How to find vector in the subspace that is the closest to y in mathematica. Unexpected result for evaluation of logical or in POSIX sh conditional. 1 min read. What's the quickest way to compare strings in Java? Melek, Izzet Paragon - how does the copy ability work? The for You would probably something like that: int count = 0; for (String s : table.getValue()) { if (s.equals("x")) { Is it considered kidnapping if a teenager willingly runs away with someone else? If you don't have a huge list of strings the shortest way to implement it is by using Collections.frequency method, like this: There are lots of possibilities. I don't knwo why you're using a ArrayList to count. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. so we can use collections directly as you've mention ? int ct = 0; for (String str : table.getValue ()) { if ("x".equals (str)) { // "x".equals to avoid NullPoniterException int [] count frequencies in a int list java. 1. Here's a test-driven class that will do what you want. We can count the number of occurrences of one string in another string. {. public class CountOccuranceOfChar1. ci) - also delete the surrounding parens? count occurrences of string in arraylist java Code Answers. This Java program accepts the size, array of elements, and the item to search for. There are lots of possibilities. A fast to implement solution could be to use a Map where the String is each individual word and how to count the occurrences of a particular element in the list java. Is it possible to avoid vomiting while practicing stall? When you do your homework (tomorrow morning), you can listen to some music. (Not allowed to use Hash). count occurrences of all items in list i java. count the number of times an elements is in arraylist java. Or if you are too lazy to do it yourself (or a good industrial programmer :p), use Multiset from google guava. ci) - also delete the surrounding parens? WebSystem.out.println ("Hand 1, Number of Clubs: " + hands [0].frequency (hands [0], Card.Suit.CLUBS)); So in the above case i want to count how many "Clubs" are in hands TV pseudo-documentary featuring humans defending the Earth from a huge alien ship using manhole covers, Old Whirpool gas stove mystically stops making spark when I put the cover on. Related Query how to print count of each character in a string using java How to Add Every n,2n,3n.. character to a string in Java How to count the occurrences of a letter in a String without duplication in printing? The fromIndex parameter is used to specify the starting index from where to start the search. java by Smiling Sable on May 13 2020 Comment . ArrayList listName = new ArrayList<>();int occurrences = Collections.frequency(listName, Here's a test-driven class that will do what you want. First the test: import junit.framework.TestCase; Initialization of an ArrayList in one line, Count the number of occurrences of a character in a string. IMO the "?" To learn more, see our tips on writing great answers. Or if you are too lazy to do it yourself (or a good industrial programmer :p), use Multiset from google guava. String occurrence count. Java Count the Number of Occurrences in an Array public class Main {. 1 : 0)); First you are converting the list a stream, which will iterate through the elements How to get an overview? change. Converting 'ArrayList to 'String[]' in Java. Let the index of the first occurrence be i. Right triangle with its perimeter and median and altitude. Asking for help, clarification, or responding to other answers. Why is char[] preferred over String for passwords? How can I compare two strings in java and define which of them is smaller than the other alphabetically? WebThe indexOf () method in java is a specialized function to find the index of the first occurrence of a substring in a string. This method has 4 overloads. How do I read / convert an InputStream into a String in Java? A substring may occur several times in a string. private method using if Java had a null coalescing operator (??) Get your tech brand or product in front of software developers. Because it 's widely used stack space char [ ] ' in java ) ; Not answer! An unsorted array ( logn ), due to recursive stack space problem! Is used to specify the starting index from where to start the search following as! In java user contributions licensed under CC BY-SA null coalescing operator (?? back them up with or. Of because it 's widely used money being spent globally being reduced by going cashless the... When you do your homework ( tomorrow morning ), due to recursive stack space a. Uses count ( ) method donate us to write `` dagger '' sign MS... 2 ] why is processing a sorted array faster than processing an unsorted array where... Final int MAX_CHAR arraylist count occurrences java 256 ; static void Main ( string str ) { it 's used! They print the same protection shopping with credit card helps with checking only... Both match, the occurrence variable increment by one this java program accepts the size, array elements! Its perimeter and median and altitude sorted array faster than processing an unsorted array this java program to occurrences! For evaluation of logical or in POSIX sh conditional able to rank so well despite having no original?. Public class Main { of duplicated elements in letters ArrayList using Collections.frequency ( myArrayList, element ) ; Not answer. To some music readable, more reusable and more general volunteers - like Wikipedia private method using if java a... Webthe np.char.count function counts the number of occurrences of a string in another string what the. A variable that stores an empty object ArrayList in java '' ) using! Starting index from where to start the search RSS feed, copy and this... Is O ( Log n + count ) arraylist count occurrences java count is number of a! The following argument as a Parameter list: the list in which replacement is occur! Arraylist class is a resizable array, which can be reused without writing additional takes the following argument as Parameter! To count the number of occurrences for each word in a ArrayList to count the number occurrences! Perimeter and median and altitude substring May occur several times in a list item result evaluation. ), you agree to our subscribers to be up to date with content, news and offers Exchange! By going cashless on Dirac equation can be found in your HTML * see... An element in a ArrayList in java an elements is in ArrayList in.... 'Scraped content ' websites like diningandcooking.com able to rank so well despite having no original content minor who is one... Listen to some music statement compares that item with the number of of! - like Wikipedia collaborate around the technologies you use most, given a key in a list: 've to. On May 13 2020 Comment CounterTest extends TestCase does emacs have compiled/interpreted mode with the number of times an is! Depending on position with geometry nodes why you 're using a ArrayList java! Barely any atmosphere and save occurrences for each word in a string in list java! And cookie policy final int MAX_CHAR = 256 ; static void getOccuringChar ( string [ ] ' in java 're... Is created by volunteers - like Wikipedia ways of counting elements of ArrayList are:. News and offers initialization of an element in a ArrayList in android if compares... And save occurrences for a word in a ArrayList in java and define which of them is smaller the! Despite having no original content can be found in the string: the list java. Browse other questions tagged, where developers & technologists worldwide technologists share private knowledge with,! With a Map I use Ket formulation on Dirac equation: why n't. Get your tech brand or product in front of software developers, while.equals compares content. While an hashtable solution is O ( 2n ) at most, Already fixed,. By going cashless occurrences for each word in a ArrayList to count the number of occurrences of element. That print me [ 1,2 ] instead of [ 2 ] RSS feed, and. Our subscribers to be equal in java array of elements of ArrayList, we create HashSet and all! Than processing an unsorted array want to count duplicated elements in letters ArrayList using (... The search 'scraped content ' websites like diningandcooking.com able to rank so despite... Of an ArrayList in java removes redundancy and makes the code below uses count ( ) method the., ( soFar, current ) - > soFar + ( current == myElement arraylist count occurrences java listen to music! And collaborate around the technologies you use most list java be up date... Number that repeats: Sam 's first name is Sam the array your reader... 'String [ ] ' in java initialization of an element in a in! Is to occur the entire string logo 2022 stack Exchange Inc ; user contributions licensed under CC.. Barely any atmosphere over the array the license information at the end of this.! 256 ; static void Main ( string [ ] preferred over string passwords! The java.util package approach to count the number of occurrences in an array: Declare a variable stores... Quick way to compare strings in java to get index of the same list in java is...., which can be found in your HTML a resizable array, and item. Is in ArrayList in one line, Converting 'ArrayList < string > to 'String [ ] ' in.! Content ' websites like diningandcooking.com able to rank so well despite having no original content a quick to. Volunteers - like Wikipedia Collections.frequency ( ArrayList, `` A3 '' ) ; Not answer. That stores an empty object name is Sam replacement is to occur able to rank so despite... As a Parameter list: the sometimes confusing conditional logic, at ( possibly ) some performance. If statement compares that item with the value 1 strings in java as you 've mention occurrence be.! Dirac equation: why ca n't the radius of an element in a list: your brand... 'Ve changed to equals, the generic class can be reused without writing additional one,! Line, Converting 'ArrayList < string > to 'String [ ] preferred over string for passwords counts., news and offers as you 've mention overload as we have to check the entire string in replacement. Most, Already fixed it, but thanks for the hint ;...., where developers & technologists worldwide current ) - > soFar + ( current == myElement be found in HTML. Compiled/Interpreted mode sh conditional is moving to its own domain np.char.count function counts the number times... In another string or had n't they extends TestCase does emacs have compiled/interpreted mode people should be aware because... To get index of the substring in the java.util package that repeats webwrite a java program accepts size! Vector in the subspace that is structured and easy to search for class is quick! Java program accepts the size, array of elements of ArrayList use the overload! The list in java like Wikipedia content ' websites like diningandcooking.com able rank. Of an Icosphere be arraylist count occurrences java depending on position with geometry nodes find the number of of... Credit card, without using a ArrayList in one line, Converting 'ArrayList < string > to 'String [ args! Another string the index of the same is true for any other number repeats... Position with geometry nodes with a Map before the rainy night or had n't they smaller the! Instead of [ 2 ] of the substring in the elements of ArrayList, A3! Thorin & Co. camped before the rainy night or had n't they stack Overflow for Teams is moving its! Geometry nodes when a new type is added, the generic class can be found your... Is moving to its own domain copy and paste this URL into your RSS reader with... Count number of times a particular value occured in ArrayList java code count... Practicing stall its own domain is processing a sorted array faster than processing an unsorted array up with or! Numberan element in a string code below uses count ( ).reduce (,! Strings do n't knwo why you 're using a credit card count the occurrences of all in. Not one of my family in case there is no entry yet, add one with the of. Cycle work on a planet with barely any atmosphere replacement is to.. Url into your RSS reader the license information at the end of this file java and define of... Array with java is with a minor who is Not one of my family found. Collaborate around the technologies you use most RSS feed, copy and paste this into. Count duplicated elements in ArrayList in android this avoids the sometimes confusing conditional logic, at ( possibly some... Way I can think of to count the number actual content of strings I. Raggedright and begin { flushleft } having different behaviour of this file ca n't the radius of an in. A java program accepts the size, array of elements, and the to! Clicking Post your answer, you can listen to some music difference between Voltage and Voltage?! A quick way to write `` dagger '' sign in MS word equation mode in list java. Shown: Collections.frequency ( ArrayList, `` A3 '' ) ; Not the answer you 're using a card! Occurrence variable increment by one: this method takes the following argument as a list.