• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comapring values in java LIST  RSS feed

 
Gaurav Sharma
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have list in key values, which is returned as below:

Name=GARRY; Type=PQANS; ID=ITCPANS175490;

I want to compare Type substring(2,5) value-'ANS' with ID substring(3,6) value-'ANS'. If these two values are different then I have to redirect the user to some other page(I can do this part).

Can anyone please help how can i compare the values?

Regards
Gaurav
 
Andrey Kozhanov
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two general possibilities to compare values:

1. Your class should implement 'java.lang.Comparable<T>' interface;
2. You may write your own class to compare values - this class should implement 'java.util.Comparator<T>' interface.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think .equals will work here just as well. The issue is how to get these values. I can think of a few ways:
- using String.split - first with ; then with =
- use a regex
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!