954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

string array

can anyone tel wat error i made in the below code..I want to assign the list of strings stored in one variable to one string array.wordlist contains list of variables.

for (int s=0; s <=wordlist; s++)
	    {
		String wordlisting[s]=new wordlist;
		System.out.println(wordlisting[s]);
            }


error

D:\program files\Java\jdk1.5.0\bin>javac Main.java
Main.java:86: ']' expected
String wordlisting[s]=new wordlist;
^
1 error

abar_sow
Light Poster
36 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

The whole for statement is wrong!

Can you explain what you trying to achive?

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

want to stroe the variable which contains the list of strings to one array..

abar_sow
Light Poster
36 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Do you have any specific reason to change from List to Array? I think that data are better kept in List which can dynamicaly grow then in fix size array...

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

i want to check for the list of duplicates in the variable...
Can i add the strings to the array and form a set to check for dups..
Give ur suggestions

abar_sow
Light Poster
36 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 
if( m.group(2).equalsIgnoreCase("NN"))
 {
      list = m.group(1);
      Set<String> s = new HashSet<String>();	
      if(!s.add(list))
  	System.out.println("Dups" +list);   	
         return list;
 }


list is a variable tat contains list of strings.
I want to check duplicates in that variable.
but here its not printing any..
Can anyone figure or suggs pls.

abar_sow
Light Poster
36 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

code

import java.io.*;
import java.util.*;
class Duplicate
{
 public static void main(String args[]){
	Set<String> s = new HashSet<String>();
	String arr[]={"hi","hello","hi","hello","how","are"};
        for(int i=0;i<arr.length;i++)
	{
        	if(!s.add(arr[i]))
	 	System.out.println("duplicates are" +arr[i]);
	}
  }
}

D:\program files\Java\jdk1.5.0\bin>java Duplicate
duplicates arehi
duplicates arehello

while passing list variable in the previous code its not printing anything.

abar_sow
Light Poster
36 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 
if( m.group(2).equalsIgnoreCase("NN"))
 {
      list = m.group(1);
      Set<String> s = new HashSet<String>();    
      if(!s.add(list))
      System.out.println("Dups" +list);       
         return list;
 }
list is a variable tat contains list of strings. I want to check duplicates in that variable. but here its not printing any.. Can anyone figure or suggs pls.


"list" looks to be a single string here. Not sure why you call it a list. Also, you are creating a new Set before you add "list" to it. It's not going to contain dupes if you only added one thing to it. Not sure why are you returning from the method in the middle of your if statement either.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You