• 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

compare values in String array

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have 2 String array one is super of other and i have to get all values which are not in sub array:chname2-subarray and chname1-super array
for(int j=0;j<chname2.length;j++)
{
for(int k=0;k<chname1.length;k++)
{
if(!chname1[k].equals(chname2[j]))
out.println(chname1[k]);
}
}
I'm not getting the values which not equal
and i want them to be printed only once is the logic proper?
Can anyone help me?
 
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct this

class Array{

public static void main(String arg[]){

String chname1[]={"Hello", "I", "Am", "Here", "why", "You", "Going"};
String chname2[]={"Hello", "I", "Am", "Here"};
for(int j=0;j<chname1.length;j++)
{
int count=0;
int y=0;
for(int k=0;k<chname2.length;k++)
{
if(chname1[j].equals(chname2[k]))
{
continue;
}
else
count++;
y=j;
}
if(count==chname2.length)
System.out.println(chname1[y]);
}

}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic