Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Extract multiple integers from a String in Java

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Demo {
	public static void main(String[] args) {
		String str = "(29, 12; 29, ) (45, 67; 78, 80)";
		Matcher matcher = Pattern.compile("\\d+").matcher(str);
		List<Integer>list = new ArrayList<Integer>();
		while(matcher.find()) {
			list.add(Integer.parseInt(matcher.group()));
		}
		System.out.println("Integers = "+list);
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.