Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to find the first character which occurs only once in string?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string "refer reference-book" and I want to find the first character which occurs only once, in this string I have 2 characters which occurs only once which is a space " " and a hyphen "-" but the first character is space " " so I want to return that from a method.

How to do this?
 
Saloon Keeper
Posts: 12154
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Related threads:
https://coderanch.com/t/731064/java/Find-times-case-sensitive-string
https://coderanch.com/t/731062/java/find-elements-occurred-ArrayList-Java

Try out the solutions given in the related threads. Then if you can't work out how to extend those solutions to this problem, tell us what you've tried and what you're stuck on.
 
Master Rancher
Posts: 3876
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose of this assignment?  To learn how to use Stream or to learn about accessing arrays?
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic