Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write program to print Hello World and print each character
address in that string and print how many times each
character is in that string?
Ex: H: 0 & 1
e:1 & 1
l :2,3,8 & 3
o:4,6 & 2
w:5 & 1
r: 7 & 1
d 9 & 1

Answer Posted / jishnu

Sorry I dont want to give a detailed answer here cos no one e is going to read the code.

You can use Map<Char,List<Integer>> counterMap

Iterate through the length of the string
for(int i=i; i<s.length();i++){
if(counterMap.get(s.getCharAt(i))==nul){
//First time
List<Integer> a= new ArrayList<Integer>();
a.add(i);
counterMap.put(s.getCharAt(i),a);
}else{
counterMap.get(s.getCharAt(i)).add(i);
}


//We can iterate through keySet or entrySet to show the result
}


Regards,
Jishnu

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is 0 true or is 1 true?

906


What is the size of integer?

1048


Is a char always 1 byte?

933


What does localhost mean?

887


How do you declare an empty string?

1010


How many types of gc are there in java?

935


How do you remove an object from an arraylist in java?

907


Does a class inherit the constructors of its superclass in java programming?

1014


What do you mean by scope of variable?

831


What does isempty () do in java?

1002


What is floor in java?

991


Which api is provided by java for operations on set of objects?

1399


What are the java ide’s?

984


What is object cloning in Java?

1059


can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread

932