Hello
I am having problems with parsing a String array so that i could format it in a way that i could convert it to an integer.
Here is piece of the code:

String names[] = something.toArray( new String[something.size()]);
		String strNames= new String();
		String parse = new String();
		for (int x=0; x<something.size(); x++){
			strNames = names[x];
				
			parse = parse + strNames.replaceAll("\\D", "")+ System.getProperty("line.separator");
			
			
		}
		
		System.out.println(parse);

When i use System.getProperty("line.separator") ,so the next number would start as a new line, multiple blank lines get created in the process. Those blank lines are created where the stripped stuff used to be.
Can you please help me with this?
thanks

If you want to parse a String into Integers, use the method Integer.parseInt(stringParseableAsIntHere). If you're sending the String to a char array, you could use the " + " operator and "" to put it back as a String and use the parseInt method.

Hello
I am having problems with parsing a String array so that i could format it in a way that i could convert it to an integer.

honestly, I'm not sure as to what you're trying to do here.
if I'm correct, you're either trying to convert the contents of a String to a numerical format:

as in

String numbers = "325 568";

here you can use the String method indexOf(" ") to seperate the numbers, after which you can add the next found number into a collection. to parse it, you get, as BestJewSinceJC already pointed out:

int number = Integer.parseInt(numbers.findNextNumber());

or, I'm wrong with my assumption, and you're having an Array of Strings

String[] numbers = {"385","556"};

and you want to convert that to numbers

int numberList[] = new int[numbers.length];
for ( int i = 0; i < numbers.length; i++){
  numberList [i] = Integer.parseInt(numbers[i]);
}

Ok, i looked at my code an it seems that i am doing redundant work. I don't think there should be a reason for me to convert the array list to String array. I changed my code to this:

String strNames= new String();
		String parse = new String();
		
		
		
		
		for (int x=0; x<something.size(); x++){
			strNames = something.get(x);
			parse = parse + strNames.replaceAll("\\D", "");	
		}

THe output of the parse string looks like this : "3434" on the console.
No space between 34,and 34. Is the format of parse string like this ,String parse = "34 34",? and the system prints it like 3434 instead?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.