0

I have knowledge of wrapper class methods, but I want to know how to convert the component of String[] or Object[] to other type like int,float or Date format. for example

BufferedReader br = new BufferedReader(new FileReader(csvfile));
String curr;
while((scurr=br.readLine())!null) {
String[] input = scurr.split(",");
}

Now I want assign the component of String to primitive type(assume that my input string contains integer value)

but when I am trying to do

int i = input[0]

I am getting following suggestions: 1. change the type of i to String or 2. change the type of input to int

Is there any way to tackle the above scenario

edit:

I am really sorry guys, I really don't want ask duplicate questions, but after going through your answers and analyzing my scenario, I understood my mistake. So I would like to delete this post. How to do that without impacting the community please guild me

Sudip7
  • 2,384
  • 3
  • 27
  • 35

1 Answers1

0

You can use Integer.parseInt() without an issue.

int i = input[0] // i is an int while input[0] is a String

Now

int i=Integer.parseInt(input[0])

will convert String to int

Integer.parseInt()

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115