• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

An array list contains "abc", 3, "xyz", 7: How can i filter the numerals and display

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An array list contains "abc", 3, "xyz", 7, ...... How can i filter the numerals and display the output?

I tried with ArrayList.contains(), but not able to get the expected output. Please can some one help me on this.

Thank you.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pseudo-code:



I assume you can write the for-loop to examine each element in the list? If you have a question about how to find whether an element is a numeral, or some other question about this, don't hesitate to post it.
 
Joshua Emerson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please let me know how to find whether it is a numeral or a string and to filter them.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joshua Emerson wrote:Please let me know how to find whether it is a numeral or a string and to filter them.



One option is to use the 'instanceof" operator to check if the object is an instance of either the String or Number class.

Henry
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Joshua Emerson wrote:Please let me know how to find whether it is a numeral or a string and to filter them.



One option is to use the 'instanceof" operator to check if the object is an instance of either the String or Number class.

Henry



True, assuming that the objects in the list are of different types. But we haven't been told that, we're left to guess.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joshua Emerson wrote:...How can i filter the numerals and display the output? ...



As it is to filter and display Numerals, we can as well do an instanceof on Number.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you have a List containing different types of values in the first place?
 
Joshua Emerson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

I'm sure we shall filter the String or Integer while defining the Array list itself. But i need the logic in one of the scenarios.

Thank you all for your guidance and helping me in resolving my big problem.

 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds as if you might have a design problem with a List of alternating Strings and ints. It suggests maybe you need a Map instead, or an object which encapsulates the two values.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic